当我在同一台机器上编译并运行以下代码语句时,我得到两个不同的时区值。
public class TimeZoneDemo {
public static void main( String args[] ){
// create time zone object
TimeZone timezone = TimeZone.getDefault();
// checking time zone value
System.out.println(timezone);
}
}
JDK 1.6.35
Tue Sep 24 06:25:03 VET 2013
sun.util.calendar.ZoneInfo[id="America/Caracas",offset=-16200000,dstSavings=0,useDaylight=false,transitions=5,lastRule=null]
JDK 1.7.02
Tue Sep 24 22:56:54 MAGT 2013
sun.util.calendar.ZoneInfo[id="Asia/Magadan",offset=43200000,dstSavings=0,useDaylight=false,transitions=66,lastRule=null]
操作系统: Window 7 64 位。
时区是根据 JVM 而不是 JDK 设置的。您可以使用以下命令针对 jvm 设置此值:
Duser.timezone="Europe/Sofia"
如果您将其传递给 JVM,那么当您更改版本时,您将始终拥有相同的时区。
神谕tài liệu关于 TimeZone.getDefault()
提到...
Gets the default TimeZone for this host. The source of the default TimeZone may vary with implementation.
Tôi là một lập trình viên xuất sắc, rất giỏi!