I have a strange problem with the Java Gregorian calendar:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SZ"); sdf.setTimeZone(TimeZone.getTimeZone("US/Pacific")); GregorianCalendar cal1 = new GregorianCalendar(TimeZone.getTimeZone("US/Pacific")); cal1.setTimeInMillis(1320566400000L); GregorianCalendar cal2 = new GregorianCalendar(TimeZone.getTimeZone("US/Pacific")); cal2.setTimeInMillis(1320570000000L); System.out.println(sdf.format(cal1.getTime())); System.out.println(sdf.format(cal2.getTime()));
I executed the above code on a machine with the default time zone = US Pacific, but the machine works in Germany.
The result is the following:
2011-11-06 01:00:00:0 -0700 2011-11-06 01:00:00:0 -0800
I really donโt understand why the result is a different time zone ... I also checked the code on another computer (Timezone = GMT by default) and it works correctly.
Does anyone have an idea why this problem occurs?
Best Michael
source share