Calendar.getTime() broken?

Advertisement
Running the following code:
int hoursToMillisec = 3600 * 1000;
TimeZone tz = TimeZone.getDefault();
System.out.println("Default time zone id: " + tz.getID());
System.out.println("Default time zone: " + tz.getDisplayName());
System.out.println("Offset from GMT: " + (double)tz.getRawOffset() / hoursToMillisec);
System.out.println((tz.useDaylightTime()) ? "uses DST": "no DST");
System.out.println("DST value: " + tz.getDSTSavings() / hoursToMillisec);
System.out.println("Current time: " + Calendar.getInstance().getTime());
Outputs:
Default time zone id: America/Denver
Default time zone: Mountain Standard Time
Offset from GMT: -7.0
uses DST
DST value: 1
Current time: Tue Mar 18 13:51:45 MDT 2008
The problem is the current time is actually:
Tue Mar 18 12:51:45 MDT 2008
Advertisement

Replay

hmmm, when i run it, i get the right time.
public static void main(String args[]){
          int hoursToMillisec = 3600 * 1000;
          TimeZone tz = TimeZone.getDefault();
          System.out.println("Default time zone id: " + tz.getID());
          System.out.println("Default time zone: " + tz.getDisplayName());
          System.out.println("Offset from GMT: " + (double)tz.getRawOffset() / hoursToMillisec);
          System.out.println((tz.useDaylightTime()) ? "uses DST": "no DST");
          System.out.println("DST value: " + tz.getDSTSavings() / hoursToMillisec);
          System.out.println("Current time: " + Calendar.getInstance(tz).getTime());
     }I get the correct answer: Tue Mar 18 15:49:06 EDT 2008 And the time here is 3:49