SimpleTimeZone
is a concrete subclass of TimeZone
that represents a time zone for use with a Gregorian calendar.
The class holds an offset from GMT, called raw offset, and start
and end rules for a daylight saving time schedule. Since it only holds
single values for each, it cannot handle historical changes in the offset
from GMT and the daylight saving schedule, except that the setStartYear
method can specify the year when the daylight
saving time schedule starts in effect.
To construct a SimpleTimeZone
with a daylight saving time
schedule, the schedule can be described with a set of rules,
start-rule and end-rule. A day when daylight saving time
starts or ends is specified by a combination of month,
day-of-month, and day-of-week values. The month
value is represented by a Calendar MONTH
field
value, such as Calendar#MARCH
. The day-of-week value is
represented by a Calendar DAY_OF_WEEK
value,
such as SUNDAY
. The meanings of value combinations
are as follows.
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.
The following are examples of parameters for constructing time zone objects.
// 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
.
Calendar
, GregorianCalendar
, TimeZone
Modifier and Type | Class and Description |
---|---|
private static class | SimpleTimeZone.
Cache values representing a single period of daylight saving time. |
Modifier and Type | Field and Description |
---|---|
private transient volatile SimpleTimeZone. | |
pack-priv static final int | |
private static final int | DOM_MODE
Constants specifying values of startMode and endMode. |
private static final int | |
private static final int | |
private static final int | |
private int | dstSavings
A positive value indicating the amount of time saved during DST in milliseconds. |
private int | endDay
This field has two possible interpretations:
|
private int | endDayOfWeek
The day of the week on which daylight saving time ends. |
private int | endMode
Variables specifying the mode of the end rule. |
private int | endMonth
The month in which daylight saving time ends. |
private int | endTime
The time in milliseconds after midnight at which daylight saving time ends. |
private int | endTimeMode
The format of endTime, either |
private static final Gregorian | |
private static final int | |
private static final int | |
private static final int | |
private final byte[] | monthLength
This field was serialized in JDK 1.1, so we have to keep it that way to maintain serialization compatibility. |
private int | rawOffset
The offset in milliseconds between this zone and GMT. |
private int | serialVersionOnStream
The version of the serialized data on the stream. |
pack-priv static final long | |
public static final int | STANDARD_TIME
Constant for a mode of start or end time specified as standard time. |
private int | startDay
This field has two possible interpretations:
|
private int | startDayOfWeek
The day of the week on which daylight saving time starts. |
private int | startMode
Variables specifying the mode of the start rule. |
private int | startMonth
The month in which daylight saving time starts. |
private int | startTime
The time in milliseconds after midnight at which daylight saving time starts. |
private int | startTimeMode
The format of startTime, either WALL_TIME, STANDARD_TIME, or UTC_TIME. |
private int | startYear
The year in which daylight saving time is first observed. |
private static final byte[] | |
private static final byte[] | |
private boolean | useDaylight
A boolean value which is true if and only if this zone uses daylight saving time. |
public static final int | UTC_TIME
Constant for a mode of start or end time specified as UTC. |
public static final int | WALL_TIME
Constant for a mode of start or end time specified as wall clock time. |
Access | Constructor and Description |
---|---|
public | SimpleTimeZone(int
The base time zone offset in milliseconds to GMT. rawOffset, String The time zone name that is given to this instance. ID)Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID with no daylight saving time schedule. |
public | SimpleTimeZone(int
The given base time zone offset from GMT. rawOffset, String The time zone ID which is given to this object. ID, int The daylight saving time starting month. Month is
a startMonth, int MONTH field value (0-based. e.g., 0
for January).The day of the month on which the daylight saving time starts.
See the class description for the special cases of this parameter. startDay, int The daylight saving time starting day-of-week.
See the class description for the special cases of this parameter. startDayOfWeek, 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. startTime, int The daylight saving time ending month. Month is
a endMonth, int MONTH field
value (0-based. e.g., 9 for October).The day of the month on which the daylight saving time ends.
See the class description for the special cases of this parameter. endDay, int The daylight saving time ending day-of-week.
See the class description for the special cases of this parameter. endDayOfWeek, int The daylight saving ending time in local wall clock time,
(in milliseconds within the day) which is local daylight
time in this case. endTime)Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time. |
public | SimpleTimeZone(int
The given base time zone offset from GMT. rawOffset, String The time zone ID which is given to this object. ID, int The daylight saving time starting month. Month is
a startMonth, int MONTH field
value (0-based. e.g., 0 for January).The day of the month on which the daylight saving time starts.
See the class description for the special cases of this parameter. startDay, int The daylight saving time starting day-of-week.
See the class description for the special cases of this parameter. startDayOfWeek, int The daylight saving time starting time in local wall clock
time, which is local standard time in this case. startTime, int The daylight saving time ending month. Month is
a endMonth, int MONTH field
value (0-based. e.g., 9 for October).The day of the month on which the daylight saving time ends.
See the class description for the special cases of this parameter. endDay, int The daylight saving time ending day-of-week.
See the class description for the special cases of this parameter. endDayOfWeek, int The daylight saving ending time in local wall clock time,
which is local daylight time in this case. endTime, int The amount of time in milliseconds saved during
daylight saving time. dstSavings)Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time. |
public | SimpleTimeZone(int
The given base time zone offset from GMT. rawOffset, String The time zone ID which is given to this object. ID, int The daylight saving time starting month. Month is
a startMonth, int MONTH field
value (0-based. e.g., 0 for January).The day of the month on which the daylight saving time starts.
See the class description for the special cases of this parameter. startDay, int The daylight saving time starting day-of-week.
See the class description for the special cases of this parameter. startDayOfWeek, int The daylight saving time starting time in the time mode
specified by startTime, int startTimeMode .The mode of the start time specified by startTime. startTimeMode, int The daylight saving time ending month. Month is
a endMonth, int MONTH field
value (0-based. e.g., 9 for October).The day of the month on which the daylight saving time ends.
See the class description for the special cases of this parameter. endDay, int The daylight saving time ending day-of-week.
See the class description for the special cases of this parameter. endDayOfWeek, int The daylight saving ending time in time mode
specified by endTime, int endTimeMode .The mode of the end time specified by endTime endTimeMode, int The amount of time in milliseconds saved during
daylight saving time. dstSavings)Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time. |
Modifier and Type | Method and Description |
---|---|
public Object | Returns: a clone of this instance.Overrides java. Returns a clone of this |
private void | |
private void | decodeRules()
Given a set of encoded rules in startDay and startDayOfMonth, decode them and set the startMode appropriately. |
private void | |
public boolean | Returns: True if the givenobj is the same as this
SimpleTimeZone object; false otherwise.The obj)SimpleTimeZone object to be compared with.Overrides java. Compares the equality of two |
public int | Returns: 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.Overrides java. Returns the amount of time in milliseconds that the clock is advanced during daylight saving time. |
private long | |
public int | Returns: the amount of time in milliseconds to add to UTC to get local time.the time at which the time zone offset is found date)Overrides java. Returns the offset of this time zone from UTC at the given time. |
public int | Returns: The milliseconds to add to UTC to get local time.The era of the given date. era, int The year in the given date. year, int The month in the given date. Month is 0-based. e.g.,
0 for January. month, int The day-in-month of the given date. day, int The day-of-week of the given date. dayOfWeek, int The milliseconds in day in standard local time. millis)Implements abstract java. Returns the difference in milliseconds between local time and UTC, taking into account both the raw offset and the effect of daylight saving, for the specified date and time. |
private int | |
pack-priv int | getOffsets(long
the milliseconds (since January 1, 1970,
00:00:00.000 GMT) at which the time zone offset and daylight
saving amount are found date, int[] an array of int where the raw GMT offset
(offset[0]) and daylight saving amount (offset[1]) are stored,
or null if those values are not needed. The method assumes that
the length of the given array is two or larger. offsets)Overrides java. Gets the raw GMT offset and the amount of daylight saving of this time zone at the given time. |
public int | Returns: the GMT offset value in millisecondsImplements abstract java. Gets the GMT offset for this time zone. |
private long | |
private long | getTransition(BaseCalendar cal, BaseCalendar.
|
public int | Returns: the hash code for this objectOverrides java. Generates the hash code for the SimpleDateFormat object. |
public boolean | Returns: true if the given zone is a SimpleTimeZone and has the
same rules and offset as this onethe TimeZone object to be compared with other)Overrides java. Returns |
public boolean | Returns: true if daylight saving time is in effective at the given date; false otherwise.the given Date. date)Implements abstract java. Queries if the given date is in daylight saving time. |
private void | |
private void | |
public boolean | Returns: true if this SimpleTimeZone observes
Daylight Saving Time; false otherwise.Overrides java. Returns |
private byte[] | |
private int[] | |
private void | |
public void | setDSTSavings(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). millisSavedDuringDST)Sets the amount of time in milliseconds that the clock is advanced during daylight saving time. |
public void | setEndRule(int
The daylight saving time ending month. Month is
a endMonth, int MONTH field
value (0-based. e.g., 9 for October).The day of the month on which the daylight saving time ends.
See the class description for the special cases of this parameter. endDay, int The daylight saving time ending day-of-week.
See the class description for the special cases of this parameter. endDayOfWeek, int The daylight saving ending time in local wall clock time,
(in milliseconds within the day) which is local daylight
time in this case. endTime)Sets the daylight saving time end rule. |
public void | setEndRule(int
The daylight saving time ending month. Month is
a endMonth, int MONTH field
value (0-based. e.g., 9 for October).The day of the month on which the daylight saving time ends. endDay, int The daylight saving ending time in local wall clock time,
(in milliseconds within the day) which is local daylight
time in this case. endTime)Sets the daylight saving time end rule to a fixed date within a month. |
public void | setEndRule(int
The daylight saving time ending month. Month is
a endMonth, int MONTH field
value (0-based. e.g., 9 for October).The day of the month on which the daylight saving time ends. endDay, int The daylight saving time ending day-of-week. endDayOfWeek, int The daylight saving ending time in local wall clock time,
(in milliseconds within the day) which is local daylight
time in this case. endTime, boolean If true, this rule selects the first after)endDayOfWeek on
or after endDay . If false, this rule
selects the last endDayOfWeek on or before
endDay of the month.Sets the daylight saving time end rule to a weekday before or after the given date within a month, e.g., the first Monday on or after the 8th. |
public void | setRawOffset(int
the given base time zone offset to GMT. offsetMillis)Implements abstract java. Sets the base time zone offset to GMT. |
public void | setStartRule(int
The daylight saving time starting month. Month is
a startMonth, int MONTH field
value (0-based. e.g., 0 for January).The day of the month on which the daylight saving time starts.
See the class description for the special cases of this parameter. startDay, int The daylight saving time starting day-of-week.
See the class description for the special cases of this parameter. startDayOfWeek, int The daylight saving time starting time in local wall clock
time, which is local standard time in this case. startTime)Sets the daylight saving time start rule. |
public void | setStartRule(int
The daylight saving time starting month. Month is
a startMonth, int MONTH field
value (0-based. e.g., 0 for January).The day of the month on which the daylight saving time starts. startDay, 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. startTime)Sets the daylight saving time start rule to a fixed date within a month. |
public void | setStartRule(int
The daylight saving time starting month. Month is
a startMonth, int MONTH field
value (0-based. e.g., 0 for January).The day of the month on which the daylight saving time starts. startDay, int The daylight saving time starting day-of-week. startDayOfWeek, int The daylight saving time starting time in local wall clock
time, which is local standard time in this case. startTime, boolean If true, this rule selects the first after)dayOfWeek on or
after dayOfMonth . If false, this rule
selects the last dayOfWeek on or before
dayOfMonth .Sets the daylight saving time start rule to a weekday before or after the given date within a month, e.g., the first Monday on or after the 8th. |
public void | setStartYear(int
The daylight saving starting year. year)Sets the daylight saving time starting year. |
public String | Returns: a string representation of this time zone.Overrides java. Returns a string representation of this time zone. |
private void | unpackRules(byte[] rules)
Given an array of bytes produced by packRules, interpret them as the start and end rules. |
private void | |
public boolean | Returns: true if this time zone uses daylight saving time; false otherwise.Implements abstract java. Queries if this time zone uses daylight saving time. |
private void | writeObject(ObjectOutputStream stream)
Save the state of this object to a stream (i.e., serialize it). |