This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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.
Joined: Sep 28, 2008
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.
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.
Joined: Mar 05, 2008
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.
Joined: Sep 28, 2008
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,
and now new Date() returns correct offset to calculate EDT..