/* * Detects the platform time zone which maps to a Java time zone ID. */char *findJavaTZ_md(const char *java_home_dir, const char *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. */static int getWinTimeZone(char *winZoneName, char *winMapID){...}时区的设置方式:
findJavaTz_md()方法的解释上写得很清楚了:将平台时区ID映射为Java时区ID
/* * findJavaTZ_md() maps platform time zone ID to Java time zone ID * using /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(const char *java_home_dir, const char *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; }#endif if (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;}步骤:
1、使用< Java home>/lib/tzmappings,。如果没有找到"TZ"变量,就举行第2步
2、 tz = getPlatformTimeZoneID(); 执行Linux特定的映射,如果找到,返回一个时区ID,否则返回null
【Linux】Centos7修改系统时区timezone方式:
timedatectl