Forum Stats

  • 3,770,351 Users
  • 2,253,099 Discussions
  • 7,875,413 Comments

Discussions

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

Bill S
Bill S Member Posts: 13
edited May 17, 2013 2:22PM in Java Runtime Environment (JRE)
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
This discussion has been closed.