程序如下:
import java.util.Calendar;
public class TestCalendar {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(1970, 0, 1);
System.out.println(calendar.getTime());
System.out.println(calendar.getTimeInMillis());
}
}
执行结果:
Thu Jan 01 00:00:00 CST 1970
-28800000
1970-01-01
理想结果:
Thu Jan 01 00:00:00 CST 1970
0
1970-01-01
问题:calendar.getTimeInMillis()返回的是
“当前时间,以从历元至现在所经过的 UTC 毫秒数形式。”
这里的当前时间就是Thu Jan 01 00:00:00 CST 1970吧,它距历元(即格林威治标准时间 1970 年 1 月 1 日的 00:00:00.000,格里高利历)的毫秒数应该是0啊。怎么是-28800000这个数字呢