当使用它们的方法java.util.Date.getTime()对java Date对象求和时,我得到了意外的结果。这是示例代码:System.out.println(d1.toString()); System.out.println(d2.toString());System.out.println(new Date(d1.getTime() + d2.getTime()));这是输出:Mon Mar 20 00:00:00 CET 2017Thu Jan 01 10:44:00 CET 1970Mon Mar 20 09:44:00 CET 2017我希望CET 2017年3月20日星期一10:44:00而不是CET 2017年3月20日星期一09:44:00。我想念什么?
3 回答
![?](http://img1.sycdn.imooc.com/54584cfb0001308402200220-100-100.jpg)
慕村9548890
TA贡献1884条经验 获得超4个赞
纪元是1970-01-01 00:00:00 UTC,而CET则是UTC +1。这是以下过程:
input: 2017-03-20 00:00:00 CET —--> 2017-03-19 23:00:00 UTC
input: 1970-01-01 10:44:00 CET —--> 1970-01-01 09:44:00 UTC
// change inputs to the long millis to epoch and sum them
2017-03-19 23:00:00 UTC + 1970-01-01 09:44:00 UTC = 2017-03-20 08:44:00 UTC
output: 2017-03-20 08:44:00 UTC —--> 2017-03-20 09:44:00 CET
添加回答
举报
0/150
提交
取消