public class SimpleTimeZone extends TimeZone
Calendar
,
GregorianCalender
,
Serialized FormConstructor 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.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o)
Returns if this object is considered equal to the other 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 millisSavedDuringDST) |
void |
setEndRule(int month,
int day,
int dayOfWeek,
int time)
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 dayOfWeek,
int time)
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, getTimeZone, setDefault, setID
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.startday
- 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.endday
- 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.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 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.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.rawOffset
- The time offset from GMT.id
- The identifier of this time zone.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 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);
You could also use in
This version doesn't suffer this inaccuracy.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 be matching the
other fields.millis
- the millis in the day (in local standard time)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 millisSavedDuringDST)
public boolean useDaylightTime()
useDaylightTime
in class TimeZone
public boolean inDaylightTime(Date date)
inDaylightTime
in class TimeZone
date
- the given Date.public int hashCode()
public boolean equals(Object o)
Object
public boolean hasSameRules(TimeZone other)
hasSameRules
in class TimeZone