java.util
Class SimpleTimeZone
- Cloneable, Serializable
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.
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.
|
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.
|
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.
|
boolean | hasSameRules(TimeZone other) - Test if the other time zone uses the same rule and only
possibly differs in ID.
|
int | hashCode() - Generates the hashCode for the SimpleDateFormat object.
|
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 , getDSTSavings , getDefault , getDisplayName , getDisplayName , getDisplayName , getDisplayName , getID , getOffset , getOffset , getRawOffset , getTimeZone , hasSameRules , inDaylightTime , setDefault , setID , setRawOffset , useDaylightTime |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
STANDARD_TIME
public static final int STANDARD_TIME
Constant to indicate that start and end times are specified in standard
time, without adjusting for daylight savings.
UTC_TIME
public static final int UTC_TIME
Constant to indicate that start and end times are specified in UTC.
WALL_TIME
public static final int WALL_TIME
Constant to indicate that start and end times are specified in wall
time, adjusting for daylight savings. This is the default.
SimpleTimeZone
public SimpleTimeZone(int rawOffset,
String id)
Create a 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.
SimpleTimeZone
public 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. 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
WEEKDAY
day < 0, dayOfWeek = Calendar.WEEKDAY
-day
WEEKDAY
end
day > 0, dayOfWeek = 0
day
day > 0, dayOfWeek = -Calendar.WEEKDAY
day
day < 0, dayOfWeek = -Calendar.WEEKDAY
- before
-day
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.
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.
SimpleTimeZone
public 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. The parameter are the same as for the constructor above, except
there is the additional dstSavaings parameter.
dstSavings
- the amount of savings for daylight savings
time in milliseconds. This must be positive.
SimpleTimeZone
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)
This constructs a new SimpleTimeZone that supports a daylight savings
rule. The parameter are the same as for the constructor above, except
there are the additional startTimeMode, endTimeMode, and dstSavings
parameters.
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.
equals
public boolean equals(Object o)
Determine whether this Object is semantically equal
to another Object.
There are some fairly strict requirements on this
method which subclasses must follow:
- It must be transitive. If
a.equals(b)
and
b.equals(c)
, then a.equals(c)
must be true as well. - It must be symmetric.
a.equals(b)
and
b.equals(a)
must have the same value. - It must be reflexive.
a.equals(a)
must
always be true. - It must be consistent. Whichever value a.equals(b)
returns on the first invocation must be the value
returned on all later invocations.
a.equals(null)
must be false.- It must be consistent with hashCode(). That is,
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 interface Object
- whether this Object is semantically equal to another
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.
- getDSTSavings in interface TimeZone
- 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);
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 interface 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)
- the time zone offset in milliseconds.
hasSameRules
public boolean hasSameRules(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.
- hasSameRules in interface TimeZone
- true if this zone uses the same rule.
hashCode
public int hashCode()
Generates the hashCode for the SimpleDateFormat object. It is
the rawOffset, possibly, if useDaylightSavings is true, xored
with startYear, startMonth, startDayOfWeekInMonth, ..., endTime.
- hashCode in interface Object
inDaylightTime
public boolean inDaylightTime(Date date)
Determines if the given date is in daylight savings time.
- inDaylightTime in interface TimeZone
- true, if it is in daylight savings time, false otherwise.
setDSTSavings
public void setDSTSavings(int dstSavings)
Sets the daylight savings offset. This is a positive offset in
milliseconds with respect to standard time.
dstSavings
- the daylight savings offset in milliseconds.
setEndRule
public void setEndRule(int month,
int day,
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.
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.
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.
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.
setEndRule
public void setEndRule(int month,
int day,
int dayOfWeek,
int time,
boolean after)
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.
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 <320 and dayOfWeek <320, 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.
setRawOffset
public void setRawOffset(int rawOffset)
Sets the standard time zone offset to GMT.
- setRawOffset in interface TimeZone
rawOffset
- The time offset from GMT in milliseconds.
setStartRule
public void setStartRule(int month,
int day,
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.
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.
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.
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.
setStartRule
public void setStartRule(int month,
int day,
int dayOfWeek,
int time,
boolean after)
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.
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 <320 and dayOfWeek <320, 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.
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.
toString
public String toString()
Returns a string representation of this SimpleTimeZone object.
- toString in interface Object
- a string representation of this SimpleTimeZone object.
useDaylightTime
public boolean useDaylightTime()
Returns if this time zone uses daylight savings time.
- useDaylightTime in interface TimeZone
- true, if we use daylight savings time, false otherwise.
java.util.SimpleTimeZone
Copyright (C) 1998, 1999, 2000, 2003, 2004, 2005, 2007
Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.