源码分析
TimeZone.getDefault() 是JDK自带的方法,所属包:java.util;方法返回此主机(程序运行的主机)的默认时区
//TimeZone类
public static TimeZone getDefault() {
return (TimeZone) getDefaultRef().clone();
}
我们来看下默认时区是怎么取值的
1、java.util.TimeZone类中getDefault方法的源代码显示,它最终是会调用sun.util.calendar.ZoneInfo类的getTimeZone 方法。这个方法为需要的时间区域返回一个作为ID的String参数。
2、时间ID zoneID的获取方式:先从JVM中的user.timezone变量中读取,如果读不到,再读取系统的默认时区
zoneID = getSystemTimeZoneID(javaHome);
/**
* Gets the platform defined TimeZone ID.
**/
private static native String getSystemTimeZoneID(String javaHome);
看到这个native ,说明已经挖到核心了,到了这一步