Timezone issues with SG timezone on Windows 2003
Hi, I created a simple java application to test out the timezone settings on a Windows 2003 server.
The server has been set to take the "(GMT +08:00) Kuala Lumpur, Singapore" timezone via the Date/Time control panel. Below is the application code and result:
-----
(Code)
import java.text.*;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
public class TestDate {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Date dt = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
System.out.println("With a java.util.Date object of "+dt+" todays date is "+df.format(dt));
System.out.println(Locale.getDefault().toString()) ;
System.out.println("Timezone: "+ TimeZone.getDefault().getID());
System.out.println("UTCOffset: " + (TimeZone.getDefault().getRawOffset()/(60*60*1000)) + " , DST:" + (TimeZone.getDefault().getDSTSavings()/(60*60*1000)));
}
}
-----
(Result)
With a java.util.Date object of Fri Jun 24 03:59:25 GMT 2011 todays date is 20110624
en_GB
Timezone: GMT
UTCOffset: 0 , DST:0
-------
When set to HongKong(China Standard Time), I get the results as expected:
-------
With a java.util.Date object of Fri Jun 24 12:00:26 CST 2011 todays date is 2011
0624
en_GB
Timezone: Asia/Shanghai
UTCOffset: 8 , DST:0
-------
Has anyone come across the above before and how can I resolve this other than explicitly setting the JVM user.timezone parameters?
Thanks.