程序后跟输出。有人请向我解释为什么从1970年1月1日开始的10,000,000毫秒是1969年11月31日。那么请有人解释我的假设:第一次测试应该从1970年1月1日开始产生10,000,000毫秒的时间,这是错误的。相同的结果。Java.util.Calendar - 1970年1月1日以来的毫秒数
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);
}
Long值:千万
日历时间以毫秒:千万
日期的YYYY-MM-DD格式为:1969年11月31日
Long值:万亿
Millis日历时间:1000000000000
在YYYY-MM-DD格式的日期:2001年8月8日
谢谢!我以为我疯了。 – 2008-11-05 00:39:48