java.util
public class SimpleTimeZone extends TimeZone
Calendar
,
GregorianCalendar
,
Serialized FormModifier and Type | Field and Description |
---|---|
static int |
STANDARD_TIME
Constant to indicate that start and end times are specified in standard
time, without adjusting for daylight savings.
|
static int |
UTC_TIME
Constant to indicate that start and end times are specified in UTC.
|
static int |
WALL_TIME
Constant to indicate that start and end times are specified in wall
time, adjusting for daylight savings.
|
Constructor and Description |
---|
SimpleTimeZone(int rawOffset,
String id)
Create a
SimpleTimeZone with the given time offset
from GMT and without daylight savings. |
SimpleTimeZone(int rawOffset,
String id,
int startMonth,
int startDayOfWeekInMonth,
int startDayOfWeek,
int startTime,
int endMonth,
int endDayOfWeekInMonth,
int endDayOfWeek,
int endTime)
Create a
SimpleTimeZone with the given time offset
from GMT and with daylight savings. |
SimpleTimeZone(int rawOffset,
String id,
int startMonth,
int startDayOfWeekInMonth,
int startDayOfWeek,
int startTime,
int endMonth,
int endDayOfWeekInMonth,
int endDayOfWeek,
int endTime,
int dstSavings)
This constructs a new SimpleTimeZone that supports a daylight savings
rule.
|
SimpleTimeZone(int rawOffset,
String id,
int startMonth,
int startDayOfWeekInMonth,
int startDayOfWeek,
int startTime,
int startTimeMode,
int endMonth,
int endDayOfWeekInMonth,
int endDayOfWeek,
int endTime,
int endTimeMode,
int dstSavings)
This constructs a new SimpleTimeZone that supports a daylight savings
rule.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o)
Determine whether this Object is semantically equal
to another Object.
|
int |
getDSTSavings()
Gets the daylight savings offset.
|
int |
getOffset(int era,
int year,
int month,
int day,
int dayOfWeek,
int millis)
Gets the time zone offset, for current date, modified in case of
daylight savings.
|
int |
getRawOffset()
Returns the time zone offset to GMT in milliseconds, ignoring
day light savings.
|
int |
hashCode()
Generates the hashCode for the SimpleDateFormat object.
|
boolean |
hasSameRules(TimeZone other)
Test if the other time zone uses the same rule and only
possibly differs in ID.
|
boolean |
inDaylightTime(Date date)
Determines if the given date is in daylight savings time.
|
void |
setDSTSavings(int dstSavings)
Sets the daylight savings offset.
|
void |
setEndRule(int month,
int day,
int time)
Sets the daylight savings end rule.
|
void |
setEndRule(int month,
int day,
int dayOfWeek,
int time)
Sets the daylight savings end rule.
|
void |
setEndRule(int month,
int day,
int dayOfWeek,
int time,
boolean after)
Sets the daylight savings end rule.
|
void |
setRawOffset(int rawOffset)
Sets the standard time zone offset to GMT.
|
void |
setStartRule(int month,
int day,
int time)
Sets the daylight savings start rule.
|
void |
setStartRule(int month,
int day,
int dayOfWeek,
int time)
Sets the daylight savings start rule.
|
void |
setStartRule(int month,
int day,
int dayOfWeek,
int time,
boolean after)
Sets the daylight savings start rule.
|
void |
setStartYear(int year)
Sets the first year, where daylight savings applies.
|
String |
toString()
Returns a string representation of this SimpleTimeZone object.
|
boolean |
useDaylightTime()
Returns if this time zone uses daylight savings time.
|
clone, getAvailableIDs, getAvailableIDs, getDefault, getDisplayName, getDisplayName, getDisplayName, getDisplayName, getID, getOffset, getTimeZone, setDefault, setID
public static final int STANDARD_TIME
public static final int WALL_TIME
public static final int UTC_TIME
public SimpleTimeZone(int rawOffset, String id)
SimpleTimeZone
with the given time offset
from GMT and without daylight savings.rawOffset
- the time offset from GMT in milliseconds.id
- The identifier of this time zone.public SimpleTimeZone(int rawOffset, String id, int startMonth, int startDayOfWeekInMonth, int startDayOfWeek, int startTime, int endMonth, int endDayOfWeekInMonth, int endDayOfWeek, int endTime)
SimpleTimeZone
with the given time offset
from GMT and with daylight savings. The start/end parameters
can have different meaning (replace WEEKDAY with a real day of
week). Only the first two meanings were supported by earlier
versions of jdk.
day > 0, dayOfWeek = Calendar.WEEKDAY
day
-th
WEEKDAY
in the given month. day < 0, dayOfWeek = Calendar.WEEKDAY
-day
-th
WEEKDAY
counted from the end of the month. day > 0, dayOfWeek = 0
day
-th day of
the month. day > 0, dayOfWeek = -Calendar.WEEKDAY
day
-th day of the month. You must make sure that
this day lies in the same month. day < 0, dayOfWeek = -Calendar.WEEKDAY
-day
-th day of the month. You
must make sure that this day lies in the same month. rawOffset
- The time offset from GMT in milliseconds.id
- The identifier of this time zone.startMonth
- The start month of daylight savings; use the
constants in Calendar.startDayOfWeekInMonth
- A day in month or a day of week number, as
described above.startDayOfWeek
- The start rule day of week; see above.startTime
- A time in millis in standard time.endMonth
- The end month of daylight savings; use the
constants in Calendar.endDayOfWeekInMonth
- A day in month or a day of week number, as
described above.endDayOfWeek
- The end rule day of week; see above.endTime
- A time in millis in standard time.IllegalArgumentException
- if parameters are invalid or out of
range.public SimpleTimeZone(int rawOffset, String id, int startMonth, int startDayOfWeekInMonth, int startDayOfWeek, int startTime, int endMonth, int endDayOfWeekInMonth, int endDayOfWeek, int endTime, int dstSavings)
dstSavings
- the amount of savings for daylight savings
time in milliseconds. This must be positive.public SimpleTimeZone(int rawOffset, String id, int startMonth, int startDayOfWeekInMonth, int startDayOfWeek, int startTime, int startTimeMode, int endMonth, int endDayOfWeekInMonth, int endDayOfWeek, int endTime, int endTimeMode, int dstSavings)
startTimeMode
- the mode that start times are specified in. One of
WALL_TIME, STANDARD_TIME, or UTC_TIME.endTimeMode
- the mode that end times are specified in. One of
WALL_TIME, STANDARD_TIME, or UTC_TIME.dstSavings
- the amount of savings for daylight savings
time in milliseconds. This must be positive.IllegalArgumentException
- if parameters are invalid or out of
range.public void setStartYear(int year)
year
- the start year.public void setStartRule(int month, int day, int dayOfWeek, int time)
setEndRule
or the result of
getOffset is undefined. For the parameters see the ten-argument
constructor above.month
- The month where daylight savings start, zero
based. You should use the constants in Calendar.day
- A day of month or day of week in month.dayOfWeek
- The day of week where daylight savings start.time
- The time in milliseconds standard time where daylight
savings start.IllegalArgumentException
- if parameters are out of range.SimpleTimeZone
public void setStartRule(int month, int day, int dayOfWeek, int time, boolean after)
setEndRule
or the result of
getOffset is undefined. For the parameters see the ten-argument
constructor above.
Note that this API isn't incredibly well specified. It appears that the
after flag must override the parameters, since normally, the day and
dayofweek can select this. I.e., if day < 0 and dayOfWeek < 0, on or
before mode is chosen. But if after == true, this implementation
overrides the signs of the other arguments. And if dayOfWeek == 0, it
falls back to the behavior in the other APIs. I guess this should be
checked against Sun's implementation.month
- The month where daylight savings start, zero
based. You should use the constants in Calendar.day
- A day of month or day of week in month.dayOfWeek
- The day of week where daylight savings start.time
- The time in milliseconds standard time where daylight
savings start.after
- If true, day and dayOfWeek specify first day of week on or
after day, else first day of week on or before.SimpleTimeZone
public void setStartRule(int month, int day, int time)
setEndRule
or the result of
getOffset is undefined. For the parameters see the ten-argument
constructor above.month
- The month where daylight savings start, zero
based. You should use the constants in Calendar.day
- A day of month or day of week in month.time
- The time in milliseconds standard time where daylight
savings start.SimpleTimeZone
public void setEndRule(int month, int day, int dayOfWeek, int time)
setStartRule
or the result of
getOffset is undefined. For the parameters see the ten-argument
constructor above.month
- The end month of daylight savings.day
- A day in month, or a day of week in month.dayOfWeek
- A day of week, when daylight savings ends.time
- A time in millis in standard time.setStartRule(int, int, int, int)
public void setEndRule(int month, int day, int dayOfWeek, int time, boolean after)
setStartRule
or the result of
getOffset is undefined. For the parameters see the ten-argument
constructor above.
Note that this API isn't incredibly well specified. It appears that the
after flag must override the parameters, since normally, the day and
dayofweek can select this. I.e., if day < 0 and dayOfWeek < 0, on or
before mode is chosen. But if after == true, this implementation
overrides the signs of the other arguments. And if dayOfWeek == 0, it
falls back to the behavior in the other APIs. I guess this should be
checked against Sun's implementation.month
- The end month of daylight savings.day
- A day in month, or a day of week in month.dayOfWeek
- A day of week, when daylight savings ends.time
- A time in millis in standard time.after
- If true, day and dayOfWeek specify first day of week on or
after day, else first day of week on or before.setStartRule(int, int, int, int, boolean)
public void setEndRule(int month, int day, int time)
setStartRule
or the result of
getOffset is undefined. For the parameters see the ten-argument
constructor above.month
- The end month of daylight savings.day
- A day in month, or a day of week in month.time
- A time in millis in standard time.setStartRule(int, int, int)
public int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis)
offset = cal.get(Calendar.ZONE_OFFSET)
+ cal.get(Calendar.DST_OFFSET);
This version doesn't suffer this inaccuracy.
The arguments don't follow the approach for setting start and end rules.
The day must be a positive number and dayOfWeek must be a positive value
from Calendar. dayOfWeek is redundant, but must match the other values
or an inaccurate result may be returned.getOffset
in class TimeZone
era
- the era of the given dateyear
- the year of the given datemonth
- the month of the given date, 0 for January.day
- the day of monthdayOfWeek
- the day of week; this must match the other fields.millis
- the millis in the day (in local standard time)IllegalArgumentException
- if arguments are incorrect.public int getRawOffset()
getRawOffset
in class TimeZone
public void setRawOffset(int rawOffset)
setRawOffset
in class TimeZone
rawOffset
- The time offset from GMT in milliseconds.public int getDSTSavings()
getDSTSavings
in class TimeZone
public void setDSTSavings(int dstSavings)
dstSavings
- the daylight savings offset in milliseconds.public boolean useDaylightTime()
useDaylightTime
in class TimeZone
public boolean inDaylightTime(Date date)
inDaylightTime
in class TimeZone
date
- the given Date.public int hashCode()
hashCode
in class Object
Object.equals(Object)
,
System.identityHashCode(Object)
public boolean equals(Object o)
Object
There are some fairly strict requirements on this
method which subclasses must follow:
a.equals(b)
and
b.equals(c)
, then a.equals(c)
must be true as well.a.equals(b)
and
b.equals(a)
must have the same value.a.equals(a)
must
always be true.a.equals(null)
must be false.a.equals(b)
must imply
a.hashCode() == b.hashCode()
.
The reverse is not true; two objects that are not
equal may have the same hashcode, but that has
the potential to harm hashing performance.This is typically overridden to throw a ClassCastException
if the argument is not comparable to the class performing
the comparison, but that is not a requirement. It is legal
for a.equals(b)
to be true even though
a.getClass() != b.getClass()
. Also, it
is typical to never cause a NullPointerException
.
In general, the Collections API (java.util
) use the
equals
method rather than the ==
operator to compare objects. However, IdentityHashMap
is an exception to this rule, for its own good reasons.
The default implementation returns this == o
.
equals
in class Object
o
- the Object to compare toObject.hashCode()
public boolean hasSameRules(TimeZone other)
hasSameRules
in class TimeZone
public String toString()
toString
in class Object
Object.getClass()
,
Object.hashCode()
,
Class.getName()
,
Integer.toHexString(int)