Kushal Paudyal Kushal Paudyal - 1 year ago 149
Java Question

How to set a JVM TimeZone Properly

I am trying to run a Java program, but it is taking a default GMT timezone instead of an 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();

Here is the output

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.

Answer Source

You can pass the JVM this param


For example


and this should do the trick. Setting the environment variable TZ also does the trick on Linux.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download