java 获取当前时区

public static String getTimeZone(){
    Calendar cal = Calendar.getInstance();
    int offset = cal.get(Calendar.ZONE_OFFSET);
    cal.add(Calendar.MILLISECOND, -offset);
    Long timeStampUTC = cal.getTimeInMillis();
    Long timeStamp = System.currentTimeMillis();
    Long timeZone = (timeStamp - timeStampUTC) / (1000 * 3600); System.out.println(timeZone.intValue());
    return String.valueOf(timeZone);

}

你可能感兴趣的:(java 获取当前时区)