Most visited

Recently visited

Added in API level 1

SimpleTimeZone

public class SimpleTimeZone
extends TimeZone

java.lang.Object
   ↳ java.util.TimeZone
     ↳ java.util.SimpleTimeZone


SimpleTimeZone是一个具体子类TimeZone ,表示一个使用格里高利历的时区。 该类包含GMT的偏移量,称为原始偏移量 ,以及夏令时时间表的开始和结束规则。 由于它只为每个值保存单个值,因此它不能处理从GMT和夏令时计划偏移的历史更改,但setStartYear方法可指定夏令时开始生效的年份。

SimpleTimeZone夏时制时间表构建SimpleTimeZone ,可以使用一组规则, 起始规则结束规则来描述时间表。 夏令时开始或结束的时间通过月份日期星期值的组合来指定。 月份值由日历MONTH字段值表示,如MARCH 日期值由日历DAY_OF_WEEK值表示,如SUNDAY 价值组合的含义如下。

The time of the day at which daylight saving time starts or ends is specified by a millisecond value within the day. There are three kinds of modes to specify the time: WALL_TIME, STANDARD_TIME and UTC_TIME. For example, if daylight saving time ends at 2:00 am in the wall clock time, it can be specified by 7200000 milliseconds in the WALL_TIME mode. In this case, the wall clock time for an end-rule means the same thing as the daylight time.

以下是构建时区对象的参数示例。


      // Base GMT offset: -8:00
      // DST starts:      at 2:00am in standard time
      //                  on the first Sunday in April
      // DST ends:        at 2:00am in daylight time
      //                  on the last Sunday in October
      // Save:            1 hour
      SimpleTimeZone(-28800000,
                     "America/Los_Angeles",
                     Calendar.APRIL, 1, -Calendar.SUNDAY,
                     7200000,
                     Calendar.OCTOBER, -1, Calendar.SUNDAY,
                     7200000,
                     3600000)

      // Base GMT offset: +1:00
      // DST starts:      at 1:00am in UTC time
      //                  on the last Sunday in March
      // DST ends:        at 1:00am in UTC time
      //                  on the last Sunday in October
      // Save:            1 hour
      SimpleTimeZone(3600000,
                     "Europe/Paris",
                     Calendar.MARCH, -1, Calendar.SUNDAY,
                     3600000, SimpleTimeZone.UTC_TIME,
                     Calendar.OCTOBER, -1, Calendar.SUNDAY,
                     3600000, SimpleTimeZone.UTC_TIME,
                     3600000)
 
These parameter rules are also applicable to the set rule methods, such as setStartRule.

也可以看看:

Summary

Constants

int STANDARD_TIME

标准时间指定的开始或结束时间模式的常量。

int UTC_TIME

指定为UTC的开始或结束时间模式的常量。

int WALL_TIME

用于指定为挂钟时间的开始或结束时间模式的常量。

Inherited constants

From class java.util.TimeZone

Public constructors

SimpleTimeZone(int rawOffset, String ID)

使用给定的基准时区偏移量与GMT和时区标识构建一个SimpleTimeZone,而不使用夏令时时间表。

SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime)

使用GMT提供的基准时区偏移量构建SimpleTimeZone,时区ID以及开始和结束夏令时的规则。

SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime, int dstSavings)

使用GMT提供的基准时区偏移量构建SimpleTimeZone,时区ID以及开始和结束夏令时的规则。

SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int startTimeMode, int endMonth, int endDay, int endDayOfWeek, int endTime, int endTimeMode, int dstSavings)

使用GMT提供的基准时区偏移量构建SimpleTimeZone,时区ID以及开始和结束夏令时的规则。

Public methods

Object clone()

返回此 SimpleTimeZone实例的克隆。

boolean equals(Object obj)

比较两个 SimpleTimeZone对象的相等性。

int getDSTSavings()

返回时钟在夏令时期间提前的时间量(以毫秒为单位)。

int getOffset(long date)

从给定时间返回UTC时间的偏移量。

int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis)

针对指定的日期和时间,返回本地时间与UTC之间的差值(以毫秒为单位),同时考虑原始偏移和夏令时的影响。

int getRawOffset()

获取此时区的GMT偏移量。

boolean hasSameRules(TimeZone other)

如果此区域具有与另一个区域相同的规则和偏移量,则返回 true

int hashCode()

生成SimpleDateFormat对象的哈希码。

boolean inDaylightTime(Date date)

查询给定日期是否在夏令时。

boolean observesDaylightTime()

如果 SimpleTimeZone观察夏令时,则返回 true

void setDSTSavings(int millisSavedDuringDST)

设置在夏令时期间提前时钟的时间量(以毫秒为单位)。

void setEndRule(int endMonth, int endDay, int endDayOfWeek, int endTime, boolean after)

将夏令时结束规则设置为某个月内给定日期之前或之后的某个工作日,例如,第8天或之后的第一个星期一。

void setEndRule(int endMonth, int endDay, int endDayOfWeek, int endTime)

设置夏季时间结束规则。

void setEndRule(int endMonth, int endDay, int endTime)

将夏令时结束规则设置为一个月内的固定日期。

void setRawOffset(int offsetMillis)

将基准时区偏移量设置为GMT。

void setStartRule(int startMonth, int startDay, int startDayOfWeek, int startTime)

设置夏令时开始规则。

void setStartRule(int startMonth, int startDay, int startTime)

将夏令时开始规则设置为一个月内的固定日期。

void setStartRule(int startMonth, int startDay, int startDayOfWeek, int startTime, boolean after)

将夏令时开始规则设置为一个月内给定日期之前或之后的某个工作日,例如,第8天或之后的第一个星期一。

void setStartYear(int year)

设置夏令时开始年份。

String toString()

返回此时区的字符串表示形式。

boolean useDaylightTime()

查询该时区是否使用夏令时。

Inherited methods

From class java.util.TimeZone
From class java.lang.Object

Constants

STANDARD_TIME

Added in API level 1
int STANDARD_TIME

标准时间指定的开始或结束时间模式的常量。

常数值:1(0x00000001)

UTC_TIME

Added in API level 1
int UTC_TIME

指定为UTC的开始或结束时间模式的常量。 例如,欧盟规则被指定为UTC时间。

常量值:2(0x00000002)

WALL_TIME

Added in API level 1
int WALL_TIME

用于指定为挂钟时间的开始或结束时间模式的常量。 挂钟时间是起始规则的标准时间,结束规则是夏令时。

常量值:0(0x00000000)

Public constructors

SimpleTimeZone

Added in API level 1
SimpleTimeZone (int rawOffset, 
                String ID)

使用给定的基准时区偏移量与GMT和时区标识构建一个SimpleTimeZone,而不使用夏令时时间表。

Parameters
rawOffset int: The base time zone offset in milliseconds to GMT.
ID String: The time zone name that is given to this instance.

SimpleTimeZone

Added in API level 1
SimpleTimeZone (int rawOffset, 
                String ID, 
                int startMonth, 
                int startDay, 
                int startDayOfWeek, 
                int startTime, 
                int endMonth, 
                int endDay, 
                int endDayOfWeek, 
                int endTime)

使用GMT提供的基准时区偏移量构建SimpleTimeZone,时区ID以及开始和结束夏令时的规则。 指定startTimeendTime以挂钟时间表示。 夏令时量假定为3600000毫秒(即一小时)。 这个构造函数相当于:


     SimpleTimeZone(rawOffset,
                    ID,
                    startMonth,
                    startDay,
                    startDayOfWeek,
                    startTime,
                    SimpleTimeZone.WALL_TIME,
                    endMonth,
                    endDay,
                    endDayOfWeek,
                    endTime,
                    SimpleTimeZone.WALL_TIME,
                    3600000)
 

Parameters
rawOffset int: The given base time zone offset from GMT.
ID String: The time zone ID which is given to this object.
startMonth int: The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January).
startDay int: The day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter.
startDayOfWeek int: The daylight saving time starting day-of-week. See the class description for the special cases of this parameter.
startTime int: The daylight saving time starting time in local wall clock time (in milliseconds within the day), which is local standard time in this case.
endMonth int: The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October).
endDay int: The day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter.
endDayOfWeek int: The daylight saving time ending day-of-week. See the class description for the special cases of this parameter.
endTime int: The daylight saving ending time in local wall clock time, (in milliseconds within the day) which is local daylight time in this case.
Throws
IllegalArgumentException if the month, day, dayOfWeek, or time parameters are out of range for the start or end rule

SimpleTimeZone

Added in API level 1
SimpleTimeZone (int rawOffset, 
                String ID, 
                int startMonth, 
                int startDay, 
                int startDayOfWeek, 
                int startTime, 
                int endMonth, 
                int endDay, 
                int endDayOfWeek, 
                int endTime, 
                int dstSavings)

使用GMT提供的基准时区偏移量构建SimpleTimeZone,时区ID以及开始和结束夏令时的规则。 假设startTimeendTime都是挂钟时间。 这个构造函数相当于:


     SimpleTimeZone(rawOffset,
                    ID,
                    startMonth,
                    startDay,
                    startDayOfWeek,
                    startTime,
                    SimpleTimeZone.WALL_TIME,
                    endMonth,
                    endDay,
                    endDayOfWeek,
                    endTime,
                    SimpleTimeZone.WALL_TIME,
                    dstSavings)
 

Parameters
rawOffset int: The given base time zone offset from GMT.
ID String: The time zone ID which is given to this object.
startMonth int: The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January).
startDay int: The day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter.
startDayOfWeek int: The daylight saving time starting day-of-week. See the class description for the special cases of this parameter.
startTime int: The daylight saving time starting time in local wall clock time, which is local standard time in this case.
endMonth int: The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October).
endDay int: The day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter.
endDayOfWeek int: The daylight saving time ending day-of-week. See the class description for the special cases of this parameter.
endTime int: The daylight saving ending time in local wall clock time, which is local daylight time in this case.
dstSavings int: The amount of time in milliseconds saved during daylight saving time.
Throws
IllegalArgumentException if the month, day, dayOfWeek, or time parameters are out of range for the start or end rule

SimpleTimeZone

Added in API level 1
SimpleTimeZone (int rawOffset, 
                String ID, 
                int startMonth, 
                int startDay, 
                int startDayOfWeek, 
                int startTime, 
                int startTimeMode, 
                int endMonth, 
                int endDay, 
                int endDayOfWeek, 
                int endTime, 
                int endTimeMode, 
                int dstSavings)

使用GMT提供的基准时区偏移量构建SimpleTimeZone,时区ID以及开始和结束夏令时的规则。 这个构造函数接受全套的开始和结束规则参数,包括startTimeendTime模式。 该模式指定wall timestandard timeUTC time

Parameters
rawOffset int: The given base time zone offset from GMT.
ID String: The time zone ID which is given to this object.
startMonth int: The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January).
startDay int: The day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter.
startDayOfWeek int: The daylight saving time starting day-of-week. See the class description for the special cases of this parameter.
startTime int: The daylight saving time starting time in the time mode specified by startTimeMode.
startTimeMode int: The mode of the start time specified by startTime.
endMonth int: The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October).
endDay int: The day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter.
endDayOfWeek int: The daylight saving time ending day-of-week. See the class description for the special cases of this parameter.
endTime int: The daylight saving ending time in time time mode specified by endTimeMode.
endTimeMode int: The mode of the end time specified by endTime
dstSavings int: The amount of time in milliseconds saved during daylight saving time.
Throws
IllegalArgumentException if the month, day, dayOfWeek, time more, or time parameters are out of range for the start or end rule, or if a time mode value is invalid.

也可以看看:

Public methods

clone

Added in API level 1
Object clone ()

返回此 SimpleTimeZone实例的克隆。

Returns
Object a clone of this instance.

equals

Added in API level 1
boolean equals (Object obj)

比较两个 SimpleTimeZone对象的相等性。

Parameters
obj Object: The SimpleTimeZone object to be compared with.
Returns
boolean True if the given obj is the same as this SimpleTimeZone object; false otherwise.

getDSTSavings

Added in API level 1
int getDSTSavings ()

返回时钟在夏令时期间提前的时间量(以毫秒为单位)。

Returns
int the number of milliseconds the time is advanced with respect to standard time when the daylight saving rules are in effect, or 0 (zero) if this time zone doesn't observe daylight saving time.

也可以看看:

getOffset

Added in API level 1
int getOffset (long date)

从给定时间返回UTC时间的偏移量。 如果在特定时间夏令时生效,则会根据夏令时数量调整偏移值。

Parameters
date long: the time at which the time zone offset is found
Returns
int the amount of time in milliseconds to add to UTC to get local time.

getOffset

Added in API level 1
int getOffset (int era, 
                int year, 
                int month, 
                int day, 
                int dayOfWeek, 
                int millis)

针对指定的日期和时间,返回本地时间与UTC之间的差值(以毫秒为单位),同时考虑原始偏移和夏令时的影响。 此方法假定开始和结束月份不同。 它还使用默认的GregorianCalendar对象作为其基础日历,例如确定闰年。 不要将此方法的结果与默认的日历GregorianCalendar以外的日历GregorianCalendar

注意:通常,客户应该使用Calendar.get(ZONE_OFFSET) + Calendar.get(DST_OFFSET)而不是调用此方法。

Parameters
era int: The era of the given date.
year int: The year in the given date.
month int: The month in the given date. Month is 0-based. e.g., 0 for January.
day int: The day-in-month of the given date.
dayOfWeek int: The day-of-week of the given date.
millis int: The milliseconds in day in standard local time.
Returns
int The milliseconds to add to UTC to get local time.
Throws
IllegalArgumentException the era, month, day, dayOfWeek, or millis parameters are out of range

getRawOffset

Added in API level 1
int getRawOffset ()

获取此时区的GMT偏移量。

Returns
int the GMT offset value in milliseconds

也可以看看:

hasSameRules

Added in API level 1
boolean hasSameRules (TimeZone other)

如果此区域与另一个区域具有相同的规则和偏移量,则返回 true

Parameters
other TimeZone: the TimeZone object to be compared with
Returns
boolean true if the given zone is a SimpleTimeZone and has the same rules and offset as this one

hashCode

Added in API level 1
int hashCode ()

生成SimpleDateFormat对象的哈希码。

Returns
int the hash code for this object

inDaylightTime

Added in API level 1
boolean inDaylightTime (Date date)

查询给定日期是否在夏令时。

Parameters
date Date: the given Date.
Returns
boolean true if daylight saving time is in effective at the given date; false otherwise.

observesDaylightTime

Added in API level 24
boolean observesDaylightTime ()

如果此SimpleTimeZone遵守夏令时,则返回true 该方法相当于useDaylightTime()

Returns
boolean true if this SimpleTimeZone observes Daylight Saving Time; false otherwise.

setDSTSavings

Added in API level 1
void setDSTSavings (int millisSavedDuringDST)

设置在夏令时期间提前时钟的时间量(以毫秒为单位)。

Parameters
millisSavedDuringDST int: the number of milliseconds the time is advanced with respect to standard time when the daylight saving time rules are in effect. A positive number, typically one hour (3600000).

也可以看看:

setEndRule

Added in API level 1
void setEndRule (int endMonth, 
                int endDay, 
                int endDayOfWeek, 
                int endTime, 
                boolean after)

将夏令时结束规则设置为某个月内给定日期之前或之后的某个工作日,例如,第8天或之后的第一个星期一。

Parameters
endMonth int: The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October).
endDay int: The day of the month on which the daylight saving time ends.
endDayOfWeek int: The daylight saving time ending day-of-week.
endTime int: The daylight saving ending time in local wall clock time, (in milliseconds within the day) which is local daylight time in this case.
after boolean: If true, this rule selects the first endDayOfWeek on or after endDay. If false, this rule selects the last endDayOfWeek on or before endDay of the month.
Throws
IllegalArgumentException the endMonth, endDay, endDayOfWeek, or endTime parameters are out of range

setEndRule

Added in API level 1
void setEndRule (int endMonth, 
                int endDay, 
                int endDayOfWeek, 
                int endTime)

设置夏季时间结束规则。 例如,如果夏令时在挂钟时间的凌晨2点的10月的最后一个星期日结束,则可以通过调用以下setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000);来设置结束规则: setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000);

Parameters
endMonth int: The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October).
endDay int: The day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter.
endDayOfWeek int: The daylight saving time ending day-of-week. See the class description for the special cases of this parameter.
endTime int: The daylight saving ending time in local wall clock time, (in milliseconds within the day) which is local daylight time in this case.
Throws
IllegalArgumentException if the endMonth, endDay, endDayOfWeek, or endTime parameters are out of range

setEndRule

Added in API level 1
void setEndRule (int endMonth, 
                int endDay, 
                int endTime)

将夏令时结束规则设置为一个月内的固定日期。 这种方法相当于:

setEndRule(endMonth, endDay, 0, endTime)

Parameters
endMonth int: The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October).
endDay int: The day of the month on which the daylight saving time ends.
endTime int: The daylight saving ending time in local wall clock time, (in milliseconds within the day) which is local daylight time in this case.
Throws
IllegalArgumentException the endMonth, endDay, or endTime parameters are out of range

setRawOffset

Added in API level 1
void setRawOffset (int offsetMillis)

将基准时区偏移量设置为GMT。 这是添加到UTC以获取本地时间的偏移量。

Parameters
offsetMillis int: the given base time zone offset to GMT.

也可以看看:

setStartRule

Added in API level 1
void setStartRule (int startMonth, 
                int startDay, 
                int startDayOfWeek, 
                int startTime)

设置夏令时开始规则。 例如,如果夏令时在本地挂钟时间的4月的第一个星期日凌晨2点开始,则可以通过调用以下命令来设置启动规则:

setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2*60*60*1000);

Parameters
startMonth int: The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January).
startDay int: The day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter.
startDayOfWeek int: The daylight saving time starting day-of-week. See the class description for the special cases of this parameter.
startTime int: The daylight saving time starting time in local wall clock time, which is local standard time in this case.
Throws
IllegalArgumentException if the startMonth, startDay, startDayOfWeek, or startTime parameters are out of range

setStartRule

Added in API level 1
void setStartRule (int startMonth, 
                int startDay, 
                int startTime)

将夏令时开始规则设置为一个月内的固定日期。 这种方法相当于:

setStartRule(startMonth, startDay, 0, startTime)

Parameters
startMonth int: The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January).
startDay int: The day of the month on which the daylight saving time starts.
startTime int: The daylight saving time starting time in local wall clock time, which is local standard time in this case. See the class description for the special cases of this parameter.
Throws
IllegalArgumentException if the startMonth, startDayOfMonth, or startTime parameters are out of range

setStartRule

Added in API level 1
void setStartRule (int startMonth, 
                int startDay, 
                int startDayOfWeek, 
                int startTime, 
                boolean after)

将夏令时开始规则设置为一个月内给定日期之前或之后的某个工作日,例如,第8天或之后的第一个星期一。

Parameters
startMonth int: The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January).
startDay int: The day of the month on which the daylight saving time starts.
startDayOfWeek int: The daylight saving time starting day-of-week.
startTime int: The daylight saving time starting time in local wall clock time, which is local standard time in this case.
after boolean: If true, this rule selects the first dayOfWeek on or after dayOfMonth. If false, this rule selects the last dayOfWeek on or before dayOfMonth.
Throws
IllegalArgumentException if the startMonth, startDay, startDayOfWeek, or startTime parameters are out of range

setStartYear

Added in API level 1
void setStartYear (int year)

设置夏令时开始年份。

Parameters
year int: The daylight saving starting year.

toString

Added in API level 1
String toString ()

返回此时区的字符串表示形式。

Returns
String a string representation of this time zone.

useDaylightTime

Added in API level 1
boolean useDaylightTime ()

查询该时区是否使用夏令时。

Returns
boolean true if this time zone uses daylight saving time; false otherwise.

Hooray!