anexplore
2015-08-19 23:36:42 +08:00
看一下 java.util.TimeZone 的获取 timezone 的源码吧,
private static synchronized TimeZone setDefaultZone () {
TimeZone tz;
// get the time zone ID from the system properties
String zoneID = AccessController.doPrivileged (
new GetPropertyAction ("user.timezone"));
// if the time zone ID is not set (yet ), perform the
// platform to Java time zone ID mapping.
if (zoneID == null || zoneID.isEmpty ()) {
String country = AccessController.doPrivileged (
new GetPropertyAction ("user.country"));
String javaHome = AccessController.doPrivileged (
new GetPropertyAction ("java.home"));
try {
zoneID = getSystemTimeZoneID (javaHome, country );
if (zoneID == null ) {
zoneID = GMT_ID;
}
} catch (NullPointerException e ) {
zoneID = GMT_ID;
}
}}
。。。。。。。。。。
}