java.util.TimeZone.setDefault()方法 java.util.TimeZone.inDaylightTime() java.util.TimeZone.setID() 描述 所述setDefault(TimeZone zone)方法被用于设置由getDefault方法返回的时区。 声明 以下是java.util.TimeZone.setDefault()方法的声明。 public static void setDefault(TimeZone zone) 参数 zone - 这是新的默认时区 返回值 NA 异常 NA 实例 以下示例显示了java.util.TimeZone.setDefault()的用法 package com.tutorialspoint; import java.util.*; public class TimeZoneDemo { public static void main( String args[] ) { // create time zone object TimeZone tzone = TimeZone.getTimeZone("America/Los_Angeles"); // set time zone to default tzone.setDefault(tzone); // checking default time zone System.out.println("Default time zone:" +tzone); } } 让我们编译并运行上面的程序,这将产生以下结果。 Default time zone:sun.util.calendar.ZoneInfo[id = "America/Los_Angeles", offset = -28800000,dstSavings = 3600000,useDaylight = true,transitions = 185, lastRule = java.util.SimpleTimeZone[id = America/Los_Angeles,offset = -28800000, dstSavings = 3600000,useDaylight = true,startYear = 0,startMode = 3,startMonth = 2, startDay = 8,startDayOfWeek = 1,startTime = 7200000,startTimeMode = 0,endMode = 3, endMonth = 10,endDay = 1,endDayOfWeek = 1,endTime = 7200000,endTimeMode = 0]] java.util.TimeZone.inDaylightTime() java.util.TimeZone.setID()