baozi1chi1 2011-07-26 17:32
浏览 264
已采纳

(转)一个百度的问题...

SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str3 = "1927-12-31 23:54:07";
String str4 = "1927-12-31 23:54:08";
Date sDt3 = sf.parse(str3);
Date sDt4 = sf.parse(str4);
long ld3 = sDt3.getTime() /1000;
long ld4 = sDt4.getTime() /1000;
System.out.println(ld3);
System.out.println(ld4);

======
结果:
-1325491905
-1325491552
两者只差一秒,为什么结果却差353秒呢?这是怎么回事啊?

问题地址:http://zhidao.baidu.com/question/297274433.html

--------------------------
我看了这个问题,表示我不懂
问题补充
yunzhu 写道
lc4ever 写道
这个...getTime的结果是从1970.1.1,0,0开始算的...


果然,那1970年之前的应该就有点乱了

getTime在+8的中国可不是从1970.1.1,0,0开始算的
问题补充
求来个高人分析下源码啊...我道行太浅分析不来
  • 写回答

6条回答 默认 最新

  • 也许世界还没停 2011-07-28 12:01
    关注

    http://stackoverflow.com/questions/6841333/a-very-strange-date-before-1970

    It's a time zone change on December 31st in Shanghai.

    See this page for details of 1927 in Shanghai. Basically at midnight at the end of 1927, the clocks went back 5 minutes and 52 seconds. So "1927-12-31 23:54:08" actually happened twice, and it looks like Java is parsing it as the later possibly instant for that local date/time - hence the difference.

    Just another episode in the often weird and wonderful world of time zones.

    在1927年底时间修改了……

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?