Home >Java >javaTutorial >Why Does My Java Program Display GMT Time Instead of My System Timezone, and How Can I Fix it?
Overcoming Default GMT TimeZone in Java Program: A Comprehensive Guide to JVM TimeZone Configuration
Java programs often encounter the issue of displaying GMT time instead of the operating system (OS) defined timezone. This article delves into resolving this issue, particularly for JDK 1.5 running on Windows Server Enterprise (2007).
Problem Statement:
Despite the OS having a Central timezone specified, a Java program using Calendar.getInstance() may display GMT time. Customizing the timezone from within the application is not preferred; the goal is to align the JVM's timezone with the OS.
Solution:
JVM timezone customization can be achieved by passing the following parameter:
-Duser.timezone
For instance:
-Duser.timezone=Europe/Sofia
This parameter ensures that the JVM adopts the specified timezone. Alternatively, on Linux systems, setting the environment variable TZ yields similar results.
The above is the detailed content of Why Does My Java Program Display GMT Time Instead of My System Timezone, and How Can I Fix it?. For more information, please follow other related articles on the PHP Chinese website!