File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Daylight Saving Time in Java5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Daylight Saving Time in Java5" Watch "Daylight Saving Time in Java5" New topic
Author

Daylight Saving Time in Java5

Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324
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.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18655
    
    8

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

Joined: Sep 28, 2008
Posts: 324
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.

Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
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
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
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

Joined: Sep 28, 2008
Posts: 324
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Daylight Saving Time in Java5