/*
* Detects the platform time zone which maps to a Java time zone ID.
*/char*findJavaTZ_md(constchar*java_home_dir,constchar*country){char winZoneName[MAX_ZONE_CHAR];char winMapID[MAX_MAPID_LENGTH];char*std_timezone =NULL;int result;
winMapID[0]=0;
result =getWinTimeZone(winZoneName, winMapID);if(result != VALUE_UNKNOWN){if(result == VALUE_GMTOFFSET){
std_timezone =_strdup(winZoneName);}else{
std_timezone =matchJavaTZ(java_home_dir, result,
winZoneName, winMapID, country);}}return std_timezone;}
注释写得很清楚,获取“Time Zones”注册表中的当前时区
/*
* Gets the current time zone entry in the "Time Zones" registry.
*/staticintgetWinTimeZone(char*winZoneName,char*winMapID){...}
时区的设置方式:
那时区上的选择值是从哪取到的,上面有说了,是在注册表中取值
打开注册表 :Regedit–>
计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
unix系的平台
findJavaTz_md()方法的注释上写得很清楚了:将平台时区ID映射为Java时区ID
/*
* findJavaTZ_md() maps platform time zone ID to Java time zone ID
* using <java_home>/lib/tzmappings. If the TZ value is not found, it
* trys some libc implementation dependent mappings. If it still
* can't map to a Java time zone ID, it falls back to the GMT+/-hh:mm
* form. `country', which can be null, is not used for UNIX platforms.
*//*ARGSUSED1*/char*findJavaTZ_md(constchar*java_home_dir,constchar*country){char*tz;char*javatz =NULL;char*freetz =NULL;
tz =getenv("TZ");#ifdef__linux__if(tz ==NULL){#else#ifdef__solaris__if(tz ==NULL||*tz =='\0'){#endif#endif
tz =getPlatformTimeZoneID();
freetz = tz;}/*
* Remove any preceding ':'
*/if(tz !=NULL&&*tz ==':'){
tz++;}#ifdef__solaris__if(strcmp(tz,"localtime")==0){
tz =getSolarisDefaultZoneID();
freetz = tz;}#endifif(tz !=NULL){#ifdef__linux__/*
* Ignore "posix/" prefix.
*/if(strncmp(tz,"posix/",6)==0){
tz +=6;}#endif
javatz =strdup(tz);if(freetz !=NULL){free((void*) freetz);}}return javatz;}