从当前日期减去两天,在历史毫秒java [英] subtracting two days from current date in epoch milliseconds java
本文介绍了从当前日期减去两天,在历史毫秒java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
long timeInEpoch =(currentMillis()/ 1000 - (48 * 60 * 60)); // 48来自UI
public long currentMillis(){
return new Date()。getTime();
}
d = new Date(timeInEpoch * 1000);
我也尝试过
d1 = new Date(timeInEpoch);
没有什么可以工作。我在这里做错什么?
解决方案
尝试
long millis = System.currentTimeMillis() - 2 * 24 * 60 * 60 * 1000;
Date date = new Date(millis);
它绝对有效
I am trying to do something really simple. I am trying to subtract 2 days from the current day. I get the number of hours from the UI. So in this example, I get 48 hours from the UI. I am doing the following and I don't know what i'm doing wrong here. I think the result of this is it only subtracts a few minutes from the time.
long timeInEpoch = (currentMillis()/1000 - (48 * 60 * 60)); //48 comes from UI
public long currentMillis(){
return new Date().getTime();
}
d = new Date(timeInEpoch * 1000);
I also tried
d1 = new Date(timeInEpoch);
Nothing seems to work. What am I doing wrong here?
解决方案
try
long millis = System.currentTimeMillis() - 2 * 24 * 60 * 60 * 1000;
Date date = new Date(millis);
it definitely works
这篇关于从当前日期减去两天,在历史毫秒java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文