java诡异程序,不管你信不信,反正我信了
package com.xiaogu;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.TimeZone;
public class Test1{
public static void main(String[] args) throws ParseException {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sf.setTimeZone(TimeZone.getTimeZone("Asia/shanghai"));
String str3 = "1927-12-31 23:54:07";
String str4 = "1927-12-31 23:54:08";
Date date1 = sf.parse(str3);
Date date2 = sf.parse(str4);
long ld1 = date1.getTime() /1000;
long ld2 = date2.getTime() /1000;
System.out.println(ld1);
System.out.println(ld2);
System.out.println(ld2-ld1);//难道它不应该输出1吗?
}
}
答案:
-1325491905
-1325491552
353 1 楼 hareamao 2011-09-08 依照sun的描述,这是因为1928年以前,上海使用的是本地时间,而不是东八区时间。
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7070044
引用Assuming the time zone is Asia/Shanghai, Local Mean Time was used until 1928-01-01. The following is the time zone data from the Olson tzdata.
ZoneAsia/Shanghai8:05:52-LMT1928
8:00ShangC%sT1949
8:00PRCC%sT
Therefore, the transition is correct.
2 楼 kobbyla 2011-09-21 hareamao 写道依照sun的描述,这是因为1928年以前,上海使用的是本地时间,而不是东八区时间。
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7070044
引用Assuming the time zone is Asia/Shanghai, Local Mean Time was used until 1928-01-01. The following is the time zone data from the Olson tzdata.
ZoneAsia/Shanghai8:05:52-LMT1928
8:00ShangC%sT1949
8:00PRCC%sT
Therefore, the transition is correct.
Thank you...understanding