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
。 价值组合的含义如下。
MARCH
, day-of-month to 1, and day-of-week to 0.DAY_OF_WEEK
field value. For example, to specify the second Sunday of April, set month to APRIL
, day-of-month to 8, and day-of-week to -
SUNDAY
.MARCH
, day-of-month is -21 and day-of-week is -
WEDNESDAY
. DAY_OF_WEEK
value and day-of-month to -1. For example, to specify the last Sunday of October, set month to OCTOBER
, day-of-week to SUNDAY
and day-of-month to -1. 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
.
也可以看看:
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() 返回此 |
boolean |
equals(Object obj) 比较两个 |
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) 如果此区域具有与另一个区域相同的规则和偏移量,则返回 |
int |
hashCode() 生成SimpleDateFormat对象的哈希码。 |
boolean |
inDaylightTime(Date date) 查询给定日期是否在夏令时。 |
boolean |
observesDaylightTime() 如果 |
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
|
int WALL_TIME
用于指定为挂钟时间的开始或结束时间模式的常量。 挂钟时间是起始规则的标准时间,结束规则是夏令时。
常量值:0(0x00000000)
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 (int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime)
使用GMT提供的基准时区偏移量构建SimpleTimeZone,时区ID以及开始和结束夏令时的规则。 指定startTime
和endTime
以挂钟时间表示。 夏令时量假定为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 (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以及开始和结束夏令时的规则。 假设startTime
和endTime
都是挂钟时间。 这个构造函数相当于:
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 (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以及开始和结束夏令时的规则。 这个构造函数接受全套的开始和结束规则参数,包括startTime
和endTime
模式。 该模式指定wall time
或standard time
或UTC 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. |
也可以看看:
Object clone ()
返回此 SimpleTimeZone
实例的克隆。
Returns | |
---|---|
Object |
a clone of this instance. |
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. |
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. |
也可以看看:
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. |
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 |
int getRawOffset ()
获取此时区的GMT偏移量。
Returns | |
---|---|
int |
the GMT offset value in milliseconds |
也可以看看:
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 |
int hashCode ()
生成SimpleDateFormat对象的哈希码。
Returns | |
---|---|
int |
the hash code for this object |
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. |
boolean observesDaylightTime ()
如果此SimpleTimeZone
遵守夏令时,则返回true
。 该方法相当于useDaylightTime()
。
Returns | |
---|---|
boolean |
true if this SimpleTimeZone observes Daylight Saving Time; false otherwise. |
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). |
也可以看看:
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 |
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 |
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 |
void setRawOffset (int offsetMillis)
将基准时区偏移量设置为GMT。 这是添加到UTC以获取本地时间的偏移量。
Parameters | |
---|---|
offsetMillis |
int : the given base time zone offset to GMT. |
也可以看看:
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 |
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 |
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 |
void setStartYear (int year)
设置夏令时开始年份。
Parameters | |
---|---|
year |
int : The daylight saving starting year. |
String toString ()
返回此时区的字符串表示形式。
Returns | |
---|---|
String |
a string representation of this time zone. |
boolean useDaylightTime ()
查询该时区是否使用夏令时。
Returns | |
---|---|
boolean |
true if this time zone uses daylight saving time; false otherwise. |