Time zone problem moving from JDK 1.4 to 1.5

W

Wendy S

On HP-UX, we've always used 'MST7' for our timezone, and we've had no
problems until a recent move to JDK 1.5. Suddenly, all the Tomcat logs and
the webapps thought they were in GMT.

Did something officially change in the format that Java wants for timezones?
Or was 'MST7' always wrong, and it just now decided to bite us? The server
admin claims that MST7 is valid, and 'date' continues to return the correct
date and time at the prompt.

The following executes a Java program that does nothing but
System.out.println( new java.util.Date() );
under four different JDK/timezone combinations:

$ ./time.sh
JAVA_HOME is /opt/java1.4
TZ is MST7
Tue Jan 25 16:33:01 GMT-07:00 2005

JAVA_HOME is /opt/java1.4
TZ is MST
Tue Jan 25 16:33:04 MST 2005

JAVA_HOME is /opt/java1.5
TZ is MST7
Tue Jan 25 23:33:09 GMT 2005 <--- WRONG!

JAVA_HOME is /opt/java1.5
TZ is MST
Tue Jan 25 16:33:13 MST 2005
$
 
T

Thomas Weidenfeller

Wendy said:
On HP-UX, we've always used 'MST7' for our timezone, and we've had no
problems until a recent move to JDK 1.5. Suddenly, all the Tomcat logs and
the webapps thought they were in GMT.

Did something officially change in the format that Java wants for timezones?
Or was 'MST7' always wrong, and it just now decided to bite us? The server
admin claims that MST7 is valid, and 'date' continues to return the correct
date and time at the prompt.

Take the following with a gain of salt, because time zone abbreviations
are a mess. E.g. it would have helped if you would have told us where
you are, because in some areas on the globe MST is Moscow Summer Time
.... And the second problem is the non-intuitive way of Unix TZ
specifications.

Java 1.5. has apparently giving up on interpreting TZ the same twisted
way than Unix does. For example, in Unix your TZ=MST7 does not refers to
a predefined timezone, instead it is a specification (TZ=:MST7 would
have been a reference to a predefined timezone, but there is no such
date predefined). With TZ=MST7 you specify that you want to get your
time displayed with a 7 hour offset from GMT and a designation of "MST".
But with TZ=MST (better would be TZ=:MST) you refers to a predefined
timezone, which happens to have the same seven hour offset, so by some
luck you get the same time displayed.

Java 1.5 apparently doesn't do this any more. It just looks up the TZ
string in its own time zone database. If it can find the name it uses
the corresponding time zone information. If it can't find the name, it
falls back to GMT. The date display you got is correct. Just that is is
not in the desired time zone. Whether this change of interpreting TZ is
a bug or feature I don't know. Maybe you have some luck checking the
release notes and the bugparade.

A check of Java's zone info map reveals that it knows about MST and
MST7MDT, but not MST7. In general I would however recommend to use zone
names like ":US/Mountain" or ":America/Denver" or whatever and let the
system fetch the matching abbreviation from its database - if it knows
it. If not, it will fall back to GMT.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top