• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Daylight Saving Time in Java5

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am on EDT(Eastern Daylight time), it will be EST here on Nov 7th , 2011. The dates in our system were being shown in EST since last Sunda, whereas its still EDT here.
So today I was examining new Date() parameters in Java.

I saw the following.

cdate= 2010-11-03T20:24:01.248Z
zoneinfo = sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]

useDaylight must be true if I understand, does that mean Java5 is updating to EST earlier than required.

Please suggest.

 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You missed this part of the timezone: id="GMT" which explains why daylight saving time doesn't apply on that date. DST never applies in the GMT time zone.
 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

DST never applies in the GMT time zone.




Any GMT to EDT/EST conversion is done using an offset value. EDT=GMT-4, EST=GMT-5

I set the date field of a Java User object which is mapped to a database table 'User' as



This sets the time in GMT ofcourse, but when I try to retrieve it back and convert to appropriate timezone using the below faces tag, it converts it to EST (since the GMT date above was not set properly or with wrong/no offset).



EDT is extended by a week this year (From Nov1 to Nov7). And its from Nov1st like the last year we started seeing the date in EST. It should ideally be showing the date in EST after a week.

Any idea on how to set the date which is in GMT with correct offset so that I can retrieve the time correctly in EDT.

Thanks for looking.

 
Master Rancher
Posts: 4796
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most likely, you need to update the timezone files that come with your JRE. The preferred solution would be to upgrade the Java installation itself, to something more recent. You can still use Java 5 if you want, but you need a more recent patch than the one you have. Probably any version released since 2007 would do - that's when the time zone change took effect in the US. so they would have put out releases to fix this back then, if not earlier (like when the new law was passed in 2005).

If you can't get the Java version upgraded, a more minimal change that still accomplishes your goals would be to use the TZUpdater tool. This should just upgrade the time zone files, and leave other stuff alone.
 
Mike Simmons
Master Rancher
Posts: 4796
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The last line of this table suggests that Java version 5.0_u6 should be sufficient to fix your problem. Or any version of TZUpdater, since it was first created as a response to the US time zone changes. Check what Java version you're currently using - if it's already 5.0_u6 or later, then your problem is elsewhere. But I suspect you're using something older, and this is the fix.
 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Figured it out..

I override the value set in the java.lang.System.initProperties method by using the -D command-line option when launching JVM,

java -Duser.timezone=EST5EDT

and now new Date() returns correct offset to calculate EDT..

sun.util.calendar.ZoneInfo[id="EST5EDT",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=149,
lastRule=java.util.SimpleTimeZone[id=EST5EDT,offset=-18000000,dstSavings=3600000,useDaylight=true,
startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,
endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]


Thanks Mike and Paul for looking.

-Himalay
reply
    Bookmark Topic Watch Topic
  • New Topic