Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Calendar gets time wrong in Eastern Daylight

807588Jun 17 2009 — edited Jun 18 2009
I live and write code in the US Central time, it's late spring and the US is in daylight savings. I'm on vacation on the East coast where it's Eastern time and daylight savings time also applies. I've changed the time zone on my Linux machine from Chicago to New York. My program, however, thinks it's in Eastern time zone but not on daylight savings time.

How do I get the reliably correct time zone data directly from the user's computer?

JDK 1.6.0_12
NB 6.5.1
        
        Calendar cal=Calendar.getInstance();
        TimeZone tz=cal.getTimeZone();
        TimeZone man=TimeZone.getTimeZone("EST5EDT");   // because i'm the omniscient programmer who knows the user is sitting in ney york city
        System.out.println("Java says it's: "+tz.getDisplayName()+" daylight savings time is "+tz.inDaylightTime(cal.getTime()));
        System.out.println("Omniscient programmer says it's "+man.getDisplayName()+" daylight savings time is "+man.inDaylightTime(cal.getTime()));
New York:
Java says it's: GMT-05:00 daylight savings time is false
Omniscient programmer says it's Eastern Standard Time daylight savings time is true
Chicago:
Java says it's: Central Standard Time daylight savings time is true
Omniscient programmer says it's Eastern Standard Time daylight savings time is true
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 16 2009
Added on Jun 17 2009
11 comments
501 views