Skip to Main Content

Java SE (Java Platform, Standard Edition)

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!

EST, MST, and HST time zones in Java 6 and Java 7

Bill SMay 17 2013 — edited May 17 2013
Some findings on time zones, for anyone interested...

I'm not sure if this is common knowledge, but the JVM is rather inconsistent when it comes to creating USA time zones based on the commonly used 3-character names (yes, yes, we should be using 'Chicago' instead of CST/CDT and 'New_York' instead of EST/EDT, etc.). In any case, you should know that by default Central and Pacific time zones assume daylight saving but Eastern and Mountain assume no daylight saving:
System.out.println("TimeZone.getTimeZone("MST").useDaylightTime());  // --> prints 'false'
System.out.println("TimeZone.getTimeZone("CST").useDaylightTime());  // --> prints 'true'
It is defined this way because some states/counties use standard time year round. There used to be a way to force the JVM to use daylight savings for all time zones by deleting certain files (named HST, MST, and EST) or by running the tzupdater. Although the delete method has worked for me while using JRockit versions of Java 6, I've not been able to find a way to get either method to work for Sun Java 6 or Oracle Java 7.

After quite a bit of searching, I've come across a command line flag which causes Java to treat all of the US time zones as all having daylight savings. Here it is:
-Dsun.timezone.ids.oldmapping="true"
Depending on your situation, this may be helpful to you. Keep in mind if you chose to create time zones using 'MST', you have to decide what that means to your app. Daylight saving or no daylight saving? For me, it means daylight saving is observed, so I have to treat Arizona time differently (eg. GMT-7).

I hope this helps someone else who may have a similar situation.

Bill

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 14 2013
Added on May 17 2013
0 comments
664 views