プログラムと出力。1970 年 1 月 1 日から 10,000,000 ミリ秒が 1969 年 11 月 31 日である理由を誰か説明してください。最初のテストで 1970 年 1 月 1 日から 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