Timezones, Java and Windows (and therefore JBoss, and therefore PIM)

Document ID : KB000031106
Last Modified Date : 14/02/2018
Show Technical Document Details

I came across an interesting problem where a customer in the HKT (Hong Kong) timezone was having there times displayed as CST ((China) Central Standard Time) rather than HKT in ControlMinder.

My investigations led me to discover that this was to do with the way Java maps timezones from Windows, which might also be applicable to some other timezones, therefore this knowledge document.

Java has it's own ZoneInfo timezone database located <jre>\lib\zi. The mappings from Windows timezones to this ZoneInfo database is controlled by the file <jre>\lib\tzmappings. The relevant snippet for this case:

# This file describes mapping information between Windows and Java # time zones. # Format: Each line should include a colon separated fields of Windows # time zone registry key, time zone mapID, locale (which is most # likely used in the time zone), and Java time zone ID. Blank lines # and lines that start with '#' are ignored. Data lines must be sorted # by mapID (ASCII order). ... Beijing:-1,75::Asia/Shanghai: China:-1,75::Asia/Shanghai: China Standard Time:-1,75::Asia/Shanghai: ... 

There is no Hong Kong listed in the file, but the windows definition is:

(GMT +0800) Beijing, Chongqing, Hong Kong, Urumqi 

It looks like Hong Kong time in windows in mapped to Central Standard Time (CST) by java. While CST is functionally equivalent to HKT, it is not the same timezone so logically incorrect, and dates are not displayed correctly to the end user.

To confirm this I wrote and compiled the following java:

import java.util.Date;public class Main {  public static void main(String [] args) {     Date d = new Date();    System.out.println(d.toString());  }} 

When executed on a windows box with the timezone set to "(GMT +0800) Beijing, Chongqing, Hong Kong, Urumqi", this output:

Tue Jul 21 08:11:49 CST 2015

This demonstrates that Hong Kong time in windows in mapped to (China) Central Standard Time (CST) by java (i.e. nothing to do with CA Technologies software).

I tried executing this again forcing java to use the timezone of Asia/Hong_Kong by running the above with the parameter -Duser.timezone="Asia/Hong_Kong". This output:

Tue Jul 21 08:11:49 HKT 2015

This parameter can be used with JBoss to force the timezone to be Asia/Hong_Kong by stopping the JBoss service, editing <jboss>\bin\run.bat and finding the following near the end of the file:

:RESTART"%JAVA%" %JAVA_OPTS% ^   -Djava.endorsed.dirs="%JBOSS_ENDORSED_DIRS%" ^   -classpath "%JBOSS_CLASSPATH%" ^   org.jboss.Main %* -b

And modifying it to:

:RESTART"%JAVA%" %JAVA_OPTS% ^   -Djava.endorsed.dirs="%JBOSS_ENDORSED_DIRS%" ^   -classpath "%JBOSS_CLASSPATH%" ^   org.jboss.Main %* -b -Duser.timezone="Asia/Hong_Kong"

Start JBoss again and you will now see HKT instead of CST.

Please note that this is not fully tested so there may be some side effects to doing this. The only two I can think of at time of writing are:

  1. JBoss will always use Asia/Hong_Kong regardless of the timezone windows is set to
  2. If run.bat is overwritten by a patch, or JBoss is upgraded, you will need to make the change again