Program, a następnie wynik. Niech ktoś mi wyjaśni, dlaczego 10 000 000 milisekund od 1 stycznia 1970 roku to 31 listopada 1969 roku. Cóż, proszę wyjaśnić, co jest nie tak z moim założeniem, że pierwszy test powinien dać czas 10 000 000 milisekund od 1 stycznia 1970 roku. Liczby mniejsze niż 10 000 000 ten sam wynik.Java.util.Calendar - milliseconds od 1 stycznia 1970
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);
}
wartość Long: 10000000
czas Kalendarz Millis: 10000000
Data w formacie RRRR-MM-DD Format: 1969-11-31
Długi wartość: 1000000000000
Czas kalendarza w Millis: 1000000000000
Data w formacie YYYY-MM-DD: 2001-8-8
Dzięki! Myślałem, że zwariowałem. –