long rt = System.currentTimeMillis()-(1000*60*60*24*30);
当我将上述变量rt转换为日期时,我无法得到预期的日期(即)30天前。为什么?
long rt = System.currentTimeMillis()-(1000*60*60*24*30);
当我将上述变量rt转换为日期时,我无法得到预期的日期(即)30天前。为什么?
1000*60*60*24*30
的结果导致int
溢出,因为它比Integer.MAX_VALUE
大。将其更改为1000L*60*60*24*30
以使用long
。
例如:
long rt = System.currentTimeMillis()-(1000L*60*60*24*30);
System.out.println (new Date(rt));
为我打印:
Sun Feb 25 09:18:58 IST 2018
1000L
。 - shmosel