|
JavaTM 2 Platform Std. Ed. v1.4.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.TimeZone | +--java.util.SimpleTimeZone
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
,
Serialized FormField Summary | |
static int |
STANDARD_TIME
Constant for a mode of start or end time specified as standard time. |
static int |
UTC_TIME
Constant for a mode of start or end time specified as UTC. |
static int |
WALL_TIME
Constant for a mode of start or end time specified as wall clock time. |
Fields inherited from class java.util.TimeZone |
LONG, SHORT |
Constructor Summary | |
SimpleTimeZone(int rawOffset,
String ID)
Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID with no daylight saving time schedule. |
|
SimpleTimeZone(int rawOffset,
String ID,
int startMonth,
int startDay,
int startDayOfWeek,
int startTime,
int endMonth,
int endDay,
int endDayOfWeek,
int 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. |
|
SimpleTimeZone(int rawOffset,
String ID,
int startMonth,
int startDay,
int startDayOfWeek,
int startTime,
int endMonth,
int endDay,
int endDayOfWeek,
int endTime,
int 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. |
|
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)
Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time. |
Method Summary | |
Object |
clone()
Returns a clone of this SimpleTimeZone instance. |
boolean |
equals(Object obj)
Compares the equality of two SimpleTimeZone objects. |
int |
getDSTSavings()
Returns the amount of time in milliseconds that the clock is advanced during daylight saving time. |
int |
getOffset(int era,
int year,
int month,
int day,
int dayOfWeek,
int millis)
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. |
int |
getOffset(long date)
Returns the offset of this time zone from UTC at the given time. |
int |
getRawOffset()
Gets the GMT offset for this time zone. |
int |
hashCode()
Generates the hash code for the SimpleDateFormat object. |
boolean |
hasSameRules(TimeZone other)
Returns true if this zone has the same rules and offset as another zone. |
boolean |
inDaylightTime(Date date)
Queries if the given date is in daylight saving time. |
void |
setDSTSavings(int millisSavedDuringDST)
Sets the amount of time in milliseconds that the clock is advanced during daylight saving time. |
void |
setEndRule(int endMonth,
int endDay,
int endTime)
Sets the daylight saving time end rule to a fixed date within a month. |
void |
setEndRule(int endMonth,
int endDay,
int endDayOfWeek,
int endTime)
Sets the daylight saving time end rule. |
void |
setEndRule(int endMonth,
int endDay,
int endDayOfWeek,
int endTime,
boolean after)
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. |
void |
setRawOffset(int offsetMillis)
Sets the base time zone offset to GMT. |
void |
setStartRule(int startMonth,
int startDay,
int startTime)
Sets the daylight saving time start rule to a fixed date within a month. |
void |
setStartRule(int startMonth,
int startDay,
int startDayOfWeek,
int startTime)
Sets the daylight saving time start rule. |
void |
setStartRule(int startMonth,
int startDay,
int startDayOfWeek,
int startTime,
boolean after)
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. |
void |
setStartYear(int year)
Sets the daylight saving time starting year. |
String |
toString()
Returns a string representation of this time zone. |
boolean |
useDaylightTime()
Queries if this time zone uses daylight saving time. |
Methods inherited from class java.util.TimeZone |
getAvailableIDs, getAvailableIDs, getDefault, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getID, getTimeZone, setDefault, setID |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int WALL_TIME
public static final int STANDARD_TIME
public static final int UTC_TIME
Constructor Detail |
public SimpleTimeZone(int rawOffset, String ID)
rawOffset
- The base time zone offset in milliseconds to GMT.ID
- The time zone name that is given to this instance.public SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime)
startTime
and endTime
are specified to be
represented in the wall clock time. The amount of daylight saving is
assumed to be 3600000 milliseconds (i.e., one hour). This constructor is
equivalent to:
SimpleTimeZone(rawOffset,
ID,
startMonth,
startDay,
startDayOfWeek,
startTime,
SimpleTimeZone.WALL_TIME
,
endMonth,
endDay,
endDayOfWeek,
endTime,
SimpleTimeZone.WALL_TIME
,
3600000)
rawOffset
- The given base time zone offset from GMT.ID
- The time zone ID which is given to this object.startMonth
- The daylight saving time starting month. Month is
a MONTH
field value (0-based. e.g., 0
for January).startDay
- The day of the month on which the daylight saving time starts.
See the class description for the special cases of this parameter.startDayOfWeek
- The daylight saving time starting day-of-week.
See the class description for the special cases of this parameter.startTime
- 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
- The daylight saving time ending month. Month is
a MONTH
field
value (0-based. e.g., 9 for October).endDay
- The day of the month on which the daylight saving time ends.
See the class description for the special cases of this parameter.endDayOfWeek
- The daylight saving time ending day-of-week.
See the class description for the special cases of this parameter.endTime
- The daylight saving ending time in local wall clock time,
(in milliseconds within the day) which is local daylight
time in this case.
IllegalArgumentException
- if the month, day, dayOfWeek, or time
parameters are out of range for the start or end rulepublic SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime, int dstSavings)
startTime
and endTime
are assumed to be
represented in the wall clock time. This constructor is equivalent to:
SimpleTimeZone(rawOffset,
ID,
startMonth,
startDay,
startDayOfWeek,
startTime,
SimpleTimeZone.WALL_TIME
,
endMonth,
endDay,
endDayOfWeek,
endTime,
SimpleTimeZone.WALL_TIME
,
dstSavings)
rawOffset
- The given base time zone offset from GMT.ID
- The time zone ID which is given to this object.startMonth
- The daylight saving time starting month. Month is
a MONTH
field
value (0-based. e.g., 0 for January).startDay
- The day of the month on which the daylight saving time starts.
See the class description for the special cases of this parameter.startDayOfWeek
- The daylight saving time starting day-of-week.
See the class description for the special cases of this parameter.startTime
- The daylight saving time starting time in local wall clock
time, which is local standard time in this case.endMonth
- The daylight saving time ending month. Month is
a MONTH
field
value (0-based. e.g., 9 for October).endDay
- The day of the month on which the daylight saving time ends.
See the class description for the special cases of this parameter.endDayOfWeek
- The daylight saving time ending day-of-week.
See the class description for the special cases of this parameter.endTime
- The daylight saving ending time in local wall clock time,
which is local daylight time in this case.dstSavings
- The amount of time in milliseconds saved during
daylight saving time.
IllegalArgumentException
- if the month, day, dayOfWeek, or time
parameters are out of range for the start or end rulepublic 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)
startTime
and
endTime
. The mode specifies either wall
time
or standard time
or UTC
time
.
rawOffset
- The given base time zone offset from GMT.ID
- The time zone ID which is given to this object.startMonth
- The daylight saving time starting month. Month is
a MONTH
field
value (0-based. e.g., 0 for January).startDay
- The day of the month on which the daylight saving time starts.
See the class description for the special cases of this parameter.startDayOfWeek
- The daylight saving time starting day-of-week.
See the class description for the special cases of this parameter.startTime
- The daylight saving time starting time in the time mode
specified by startTimeMode
.startTimeMode
- The mode of the start time specified by startTime.endMonth
- The daylight saving time ending month. Month is
a MONTH
field
value (0-based. e.g., 9 for October).endDay
- The day of the month on which the daylight saving time ends.
See the class description for the special cases of this parameter.endDayOfWeek
- The daylight saving time ending day-of-week.
See the class description for the special cases of this parameter.endTime
- The daylight saving ending time in time time mode
specified by endTimeMode
.endTimeMode
- The mode of the end time specified by endTimedstSavings
- The amount of time in milliseconds saved during
daylight saving time.
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.WALL_TIME
,
STANDARD_TIME
,
UTC_TIME
Method Detail |
public void setStartYear(int year)
year
- The daylight saving starting year.public void setStartRule(int startMonth, int startDay, int startDayOfWeek, int startTime)
setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2*60*60*1000);
startMonth
- The daylight saving time starting month. Month is
a MONTH
field
value (0-based. e.g., 0 for January).startDay
- The day of the month on which the daylight saving time starts.
See the class description for the special cases of this parameter.startDayOfWeek
- The daylight saving time starting day-of-week.
See the class description for the special cases of this parameter.startTime
- The daylight saving time starting time in local wall clock
time, which is local standard time in this case.
IllegalArgumentException
- if the startMonth
, startDay
,
startDayOfWeek
, or startTime
parameters are out of rangepublic void setStartRule(int startMonth, int startDay, int startTime)
setStartRule(startMonth, startDay, 0, startTime)
startMonth
- The daylight saving time starting month. Month is
a MONTH
field
value (0-based. e.g., 0 for January).startDay
- The day of the month on which the daylight saving time starts.startTime
- 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.
IllegalArgumentException
- if the startMonth
,
startDayOfMonth
, or startTime
parameters are out of rangepublic void setStartRule(int startMonth, int startDay, int startDayOfWeek, int startTime, boolean after)
startMonth
- The daylight saving time starting month. Month is
a MONTH
field
value (0-based. e.g., 0 for January).startDay
- The day of the month on which the daylight saving time starts.startDayOfWeek
- The daylight saving time starting day-of-week.startTime
- The daylight saving time starting time in local wall clock
time, which is local standard time in this case.after
- If true, this rule selects the first dayOfWeek
on or
after dayOfMonth
. If false, this rule
selects the last dayOfWeek
on or before
dayOfMonth
.
IllegalArgumentException
- if the startMonth
, startDay
,
startDayOfWeek
, or startTime
parameters are out of rangepublic void setEndRule(int endMonth, int endDay, int endDayOfWeek, int endTime)
setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000);
endMonth
- The daylight saving time ending month. Month is
a MONTH
field
value (0-based. e.g., 9 for October).endDay
- The day of the month on which the daylight saving time ends.
See the class description for the special cases of this parameter.endDayOfWeek
- The daylight saving time ending day-of-week.
See the class description for the special cases of this parameter.endTime
- The daylight saving ending time in local wall clock time,
(in milliseconds within the day) which is local daylight
time in this case.
IllegalArgumentException
- if the endMonth
, endDay
,
endDayOfWeek
, or endTime
parameters are out of rangepublic void setEndRule(int endMonth, int endDay, int endTime)
setEndRule(endMonth, endDay, 0, endTime)
endMonth
- The daylight saving time ending month. Month is
a MONTH
field
value (0-based. e.g., 9 for October).endDay
- The day of the month on which the daylight saving time ends.endTime
- The daylight saving ending time in local wall clock time,
(in milliseconds within the day) which is local daylight
time in this case.
IllegalArgumentException
- the endMonth
, endDay
,
or endTime
parameters are out of rangepublic void setEndRule(int endMonth, int endDay, int endDayOfWeek, int endTime, boolean after)
endMonth
- The daylight saving time ending month. Month is
a MONTH
field
value (0-based. e.g., 9 for October).endDay
- The day of the month on which the daylight saving time ends.endDayOfWeek
- The daylight saving time ending day-of-week.endTime
- The daylight saving ending time in local wall clock time,
(in milliseconds within the day) which is local daylight
time in this case.after
- 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.
IllegalArgumentException
- the endMonth
, endDay
,
endDayOfWeek
, or endTime
parameters are out of rangepublic int getOffset(long date)
getOffset
in class TimeZone
date
- the time at which the time zone offset is found
Calendar.ZONE_OFFSET
,
Calendar.DST_OFFSET
public int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis)
GregorianCalendar
object as its
underlying calendar, such as for determining leap years. Do
not use the result of this method with a calendar other than a
default GregorianCalendar
.
Note: In general, clients should use
Calendar.get(ZONE_OFFSET) + Calendar.get(DST_OFFSET)
instead of calling this method.
getOffset
in class TimeZone
era
- The era of the given date.year
- The year in the given date.month
- The month in the given date. Month is 0-based. e.g.,
0 for January.day
- The day-in-month of the given date.dayOfWeek
- The day-of-week of the given date.millis
- The milliseconds in day in standard local time.
IllegalArgumentException
- the era
,
month
, day
, dayOfWeek
,
or millis
parameters are out of rangeCalendar.ZONE_OFFSET
,
Calendar.DST_OFFSET
public int getRawOffset()
getRawOffset
in class TimeZone
setRawOffset(int)
public void setRawOffset(int offsetMillis)
setRawOffset
in class TimeZone
offsetMillis
- the given base time zone offset to GMT.getRawOffset()
public void setDSTSavings(int millisSavedDuringDST)
millisSavedDuringDST
- 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).getDSTSavings()
public int getDSTSavings()
getDSTSavings
in class TimeZone
setDSTSavings(int)
public boolean useDaylightTime()
useDaylightTime
in class TimeZone
public boolean inDaylightTime(Date date)
inDaylightTime
in class TimeZone
date
- the given Date.
public Object clone()
SimpleTimeZone
instance.
clone
in class TimeZone
public int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
Hashtable
public boolean equals(Object obj)
SimpleTimeZone
objects.
equals
in class Object
obj
- The SimpleTimeZone
object to be compared with.
obj
is the same as this
SimpleTimeZone
object; false otherwise.Object.hashCode()
,
Hashtable
public boolean hasSameRules(TimeZone other)
hasSameRules
in class TimeZone
other
- the TimeZone object to be compared with
public String toString()
toString
in class Object
|
JavaTM 2 Platform Std. Ed. v1.4.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2002 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.