java.util
Class SimpleTimeZone
java.lang.Object
|
+--java.util.TimeZone
|
+--java.util.SimpleTimeZone
public class
SimpleTimeZoneextends
TimeZone This class represents a simple time zone offset and handles
daylight savings. It can only handle one daylight savings rule, so
it can't represent historical changes.
This object is tightly bound to the Gregorian calendar. It assumes
a regular seven days week, and the month lengths are that of the
Gregorian Calendar. It can only handle daylight savings for years
lying in the AD era.
Author:See Also:
SimpleTimeZone(int rawOffset, java.lang.String id)
|
SimpleTimeZone(int rawOffset, java.lang.String id, int startMonth, int startDayOfWeekInMonth, int startDayOfWeek, int startTime, int endMonth, int endDayOfWeekInMonth, int endDayOfWeek, int endTime)
|
SimpleTimeZone(int rawOffset, java.lang.String id, int startMonth, int startDayOfWeekInMonth, int startDayOfWeek, int startTime, int endMonth, int endDayOfWeekInMonth, int endDayOfWeek, int endTime, int dstSavings)
|
synchronized boolean | equals(java.lang.Object o)
|
int | getDSTSavings()
|
int | getOffset(int era, int year, int month, int day, int dayOfWeek, int millis)
|
int | getRawOffset()
|
boolean | hasSameRules(java.util.TimeZone other)
|
synchronized int | hashCode()
|
boolean | inDaylightTime(java.util.Date date)
|
void | setEndRule(int month, int day, int dayOfWeek, int time)
|
void | setRawOffset(int rawOffset)
|
void | setStartRule(int month, int day, int dayOfWeek, int time)
|
void | setStartYear(int year)
|
java.lang.String | toString()
|
boolean | useDaylightTime()
|
SimpleTimeZone
public SimpleTimeZone(int rawOffset, java.lang.String id)
Create a SimpleTimeZone
with the given time offset
from GMT and without daylight savings.
Parameters:
SimpleTimeZone
public SimpleTimeZone(int rawOffset, java.lang.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. 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
- The start/end of daylight savings is on the
day
-th
WEEKDAY
in the given month.
day < 0, dayOfWeek = Calendar.WEEKDAY
- The start/end of daylight savings is on the
-day
-th
WEEKDAY
counted from the end of the month.
day > 0, dayOfWeek = 0
- The start/end of daylight is on the
day
-th day of
the month.
day > 0, dayOfWeek = -Calendar.WEEKDAY
- The start/end of daylight is on the first WEEKDAY on or after
the
day
-th day of the month. You must make sure that
this day lies in the same month.
day < 0, dayOfWeek = -Calendar.WEEKDAY
- The start/end of daylight is on the first WEEKDAY on or
before the
-day
-th day of the month. You
must make sure that this day lies in the same month.
If you give a non existing month, a day that is zero, or too big,
or a dayOfWeek that is too big, the result is undefined.
The start rule must have a different month than the end rule.
This restriction shouldn't hurt for all possible time zones.
Parameters:
SimpleTimeZone
public SimpleTimeZone(int rawOffset, java.lang.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. The parameter are the same as for the constructor above, except
there is the additional dstSavaings parameter.
Parameters:
equals
public synchronized boolean equals(java.lang.Object o)
Parameters:
getDSTSavings
public int getDSTSavings()
Gets the daylight savings offset. This is a positive offset in
milliseconds with respect to standard time. Typically this
is one hour, but for some time zones this may be half an our.
Since:Returns:
- the daylight savings offset in milliseconds.
getOffset
public 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. This is the offset to add to UTC to get the local
time.
In the standard JDK the results given by this method may result in
inaccurate results at the end of February or the beginning of March.
To avoid this, you should use Calendar instead:
offset = cal.get(Calendar.ZONE_OFFSET)
+ cal.get(Calendar.DST_OFFSET);
You could also use in
This version doesn't suffer this inaccuracy.
Parameters:
Returns:
- the time zone offset in milliseconds.
getRawOffset
public int getRawOffset()
Returns the time zone offset to GMT in milliseconds, ignoring
day light savings.
Returns:
hasSameRules
public boolean hasSameRules(java.util.TimeZone other)
Test if the other time zone uses the same rule and only
possibly differs in ID. This implementation for this particular
class will return true if the other object is a SimpleTimeZone,
the raw offsets and useDaylight are identical and if useDaylight
is true, also the start and end datas are identical.
Parameters:
Returns:
- true if this zone uses the same rule.
hashCode
public synchronized int hashCode()
Generates the hashCode for the SimpleDateFormat object. It is
the rawOffset, possibly, if useDaylightSavings is true, xored
with startYear, startMonth, startDayOfWeekInMonth, ..., endTime.
inDaylightTime
public boolean inDaylightTime(java.util.Date date)
Determines if the given date is in daylight savings time.
Parameters:
Returns:
- true, if it is in daylight savings time, false otherwise.
setEndRule
public void setEndRule(int month, int day, int dayOfWeek, int time)
Sets the daylight savings end rule. You must also set the
start rule with setStartRule
or the result of
getOffset is undefined. For the parameters see the ten-argument
constructor above.
Parameters:
See Also:
setRawOffset
public void setRawOffset(int rawOffset)
Sets the standard time zone offset to GMT.
Parameters:
setStartRule
public void setStartRule(int month, int day, int dayOfWeek, int time)
Sets the daylight savings start rule. You must also set the
end rule with setEndRule
or the result of
getOffset is undefined. For the parameters see the ten-argument
constructor above.
Parameters:
See Also:
setStartYear
public void setStartYear(int year)
Sets the first year, where daylight savings applies. The daylight
savings rule never apply for years in the BC era. Note that this
is gregorian calendar specific.
Parameters:
toString
public String toString()
Returns a string representation of this SimpleTimeZone object.
Returns:
- a string representation of this SimpleTimeZone object.
useDaylightTime
public boolean useDaylightTime()
Returns if this time zone uses daylight savings time.
Returns:
- true, if we use daylight savings time, false otherwise.