我正在尝试运行 Java 程序,但它采用默认的 GMT 时区,而不是操作系统定义的时区。我的 JDK 版本是 1.5,操作系统是 Windows Server Enterprise (2007)
Windows 指定了一个中央时区,但是当我运行以下程序时,它给了我一个 GMT 时间。
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());
}
}
这是输出
sun.util.calendar.ZoneInfo[id="GMT",
offset=0,
dstSavings=0,
useDaylight=false,
transitions=0,
lastRule=null]
Mon Mar 22 13:46:45 GMT 2010
请注意,我不想从应用程序中设置时区。我希望 JVM 使用的时区应该是操作系统中指定的时区。(我没有发现其他具有 JDK 1.4 版和 Microsoft Server 2003 的服务器存在此问题)。
任何想法将不胜感激。