Tuesday, March 24, 2009

Java and the Timezones

by Fábio Souza

Timezone, when using Java, can be something tricky. You can get surprised when you change your OS timezone (something common to countries with DST) and it doesn't take any effect on your Java programs. What does Sun have to say about that? It can be found at their FAQ:

Do my operating system's timezone patches fix the Java platform's timezone data?

No. The Java SE platform's timezone data is not read from the local or host operating system. The Java SE platform maintains a private repository of timezone data in locally installed files (.../jre/lib/zi) as part of the Java Runtime Environment (JRE) software. Applying whatever operating system timezone patches (for example Solaris OS, Linux, Windows) will have no effect on the accuracy of the Java SE platform's timezone data.

Sun recommends you to maintain all JVM up to date to avoid Timezone problems. To specific cases where a Timezone update is needed, they provide a tool called TZUpdater. TZUpdater is a JAR that contains timezone informations provided by Olson Timezone Database. To update the JVM's timezone you need to execute TZUpdater's most recent version like this:

java -jar tzupdater.jar -u (don't forget to check if you have read/write access to Java's directory structure)

We are ok about Sun's JVM... But the solution is the same to all JVMs? Not really =), but it is very similar to IBM JVM and Oracle JRockit. In all cases we either have to download a program and execute it to update the installed JVM or wait for the next JVM update release.

Here are some useful links:

Sun:

IBM (thanks to my friend and co-worker Frederico Hakamine):

Oracle:

0 comments: