程序后跟输出。有人请向我解释为什么 1970 年 1 月 1 日的 10,000,000 毫秒是 1969 年 11 月 31 日。好吧,请有人解释我的假设有什么问题,即第一次测试应该从 1970 年 1 月 1 日产生 10,000,000 毫秒的时间。小于 10,000,000 的数字产生同样的结果。
public static void main(String[] args) {
String x = "10000000";
long l = new Long(x).longValue();
System.out.println("Long value: " + l);
Calendar c = new GregorianCalendar();
c.setTimeInMillis(l);
System.out.println("Calendar time in Millis: " + c.getTimeInMillis());
String origDate = c.get(Calendar.YEAR) + "-" + c.get(Calendar.MONTH) + "-" + c.get(Calendar.DAY_OF_MONTH);
System.out.println("Date in YYYY-MM-DD format: " + origDate);
x = "1000000000000";
l = new Long(x).longValue();
System.out.println("\nLong value: " + l);
c.setTimeInMillis(l);
System.out.println("Calendar time in Millis: " + c.getTimeInMillis());
origDate = c.get(Calendar.YEAR) + "-" + c.get(Calendar.MONTH) + "-" + c.get(Calendar.DAY_OF_MONTH);
System.out.println("Date in YYYY-MM-DD format: " + origDate);
}
长值:10000000
米利斯日历时间:10000000
YYYY-MM-DD 格式的日期:1969-11-31
长值:1000000000000
米利斯的日历时间:1000000000000
YYYY-MM-DD 格式的日期:2001-8-8