views:

982

answers:

1

I am trying to run a java program, but it is taking a default GMT timezone instead of a OS defined timezone. My jdk version is 1.5 and the OS is Windows Server Enterprise (2007)

Windows has a Central timezone specified, but when I run the following program, it gives me a GMT time.

import java.util.Calendar;

public class DateTest
{
    public static void main(String[] args)
    {
        Calendar now = Calendar.getInstance();
        System.out.println(now.getTimeZone());
        System.out.println(now.getTime());
    }
}

Here is the output

sun.util.calendar.ZoneInfo[id="GMT",
offset=0,
dstSavings=0,
useDaylight=false,
transitions=0,
lastRule=null]
Mon Mar 22 13:46:45 GMT 2010

Please note that I do not want to set the timezone from the application. I want that the timezone used by JVM should be the one specified in the OS. (I am not finding this issues with other servers that have version 1.4 of jdk and Microsoft Server 2003).

Any thoughts would be highly appreciated.

+4  A: 

You can pass the JVM this param -Duser.timezone, for example -Duser.timezone="Europe/Sofia" and this should do the trick. Setting the environment variable TZ might also help.

Bozhidar Batsov
We had to use the JDK DST Timezone Update Tool - 1.3.25 (tzupdater) and then change the JVM parameter as you suggested and we finally got rid of the issue.By the way, the timezone information is stored by Windows in some registry. The updater I used updated the registry values also.
Kushal Paudyal