SimpleTimeZone
open class SimpleTimeZone : TimeZone
kotlin.Any | ||
↳ | 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.
- Exact day of month
To specify an exact day of month, set the month and day-of-month to an exact value, and day-of-week to zero. For example, to specify March 1, set the month toMARCH
, day-of-month to 1, and day-of-week to 0. - Day of week on or after day of month
To specify a day of week on or after an exact day of month, set the month to an exact month value, day-of-month to the day on or after which the rule is applied, and day-of-week to a negativeDAY_OF_WEEK
field value. For example, to specify the second Sunday of April, set month toAPRIL
, day-of-month to 8, and day-of-week to-
SUNDAY
. - Day of week on or before day of month
To specify a day of the week on or before an exact day of the month, set day-of-month and day-of-week to a negative value. For example, to specify the last Wednesday on or before the 21st of March, set month toMARCH
, day-of-month is -21 and day-of-week is-
WEDNESDAY
. - Last day-of-week of month
To specify, the last day-of-week of the month, set day-of-week to aDAY_OF_WEEK
value and day-of-month to -1. For example, to specify the last Sunday of October, set month toOCTOBER
, day-of-week toSUNDAY
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.
<code> // 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) </code>
setStartRule
.
Summary
Constants | |
---|---|
static Int |
Constant for a mode of start or end time specified as standard time. |
static Int |
Constant for a mode of start or end time specified as UTC. |
static Int |
Constant for a mode of start or end time specified as wall clock time. |
Inherited constants | |
---|---|
Public constructors | |
---|---|
SimpleTimeZone(rawOffset: Int, ID: String!) Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID with no daylight saving time schedule. |
|
SimpleTimeZone(rawOffset: Int, ID: String!, startMonth: Int, startDay: Int, startDayOfWeek: Int, startTime: Int, endMonth: Int, endDay: Int, endDayOfWeek: Int, endTime: Int) 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(rawOffset: Int, ID: String!, startMonth: Int, startDay: Int, startDayOfWeek: Int, startTime: Int, endMonth: Int, endDay: Int, endDayOfWeek: Int, endTime: Int, dstSavings: Int) 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(rawOffset: Int, ID: String!, startMonth: Int, startDay: Int, startDayOfWeek: Int, startTime: Int, startTimeMode: Int, endMonth: Int, endDay: Int, endDayOfWeek: Int, endTime: Int, endTimeMode: Int, dstSavings: Int) Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time. |
Public methods | |
---|---|
open Any |
clone() Returns a clone of this |
open Boolean |
Compares the equality of two |
open Int |
Returns the amount of time in milliseconds that the clock is advanced during daylight saving time. |
open Int |
Returns the offset of this time zone from UTC at the given time. |
open Int |
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. |
open Int |
Gets the GMT offset for this time zone. |
open Boolean |
hasSameRules(other: TimeZone!) Returns |
open Int |
hashCode() Generates the hash code for the SimpleDateFormat object. |
open Boolean |
inDaylightTime(date: Date!) Queries if the given date is in daylight saving time. |
open Boolean |
Returns |
open Unit |
setDSTSavings(millisSavedDuringDST: Int) Sets the amount of time in milliseconds that the clock is advanced during daylight saving time. |
open Unit |
setEndRule(endMonth: Int, endDay: Int, endDayOfWeek: Int, endTime: Int) Sets the daylight saving time end rule. |
open Unit |
setEndRule(endMonth: Int, endDay: Int, endTime: Int) Sets the daylight saving time end rule to a fixed date within a month. |
open Unit |
Sets the daylight saving time end rule to a weekday before or after the given date within a month, e. |
open Unit |
setRawOffset(offsetMillis: Int) Sets the base time zone offset to GMT. |
open Unit |
setStartRule(startMonth: Int, startDay: Int, startDayOfWeek: Int, startTime: Int) Sets the daylight saving time start rule. |
open Unit |
setStartRule(startMonth: Int, startDay: Int, startTime: Int) Sets the daylight saving time start rule to a fixed date within a month. |
open Unit |
Sets the daylight saving time start rule to a weekday before or after the given date within a month, e. |
open Unit |
setStartYear(year: Int) Sets the daylight saving time starting year. |
open String |
toString() Returns a string representation of this time zone. |
open Boolean |
Queries if this time zone uses daylight saving time. |
Inherited functions | |
---|---|
Constants
STANDARD_TIME
static val STANDARD_TIME: Int
Constant for a mode of start or end time specified as standard time.
Value: 1
UTC_TIME
static val UTC_TIME: Int
Constant for a mode of start or end time specified as UTC. European Union rules are specified as UTC time, for example.
Value: 2
WALL_TIME
static val WALL_TIME: Int
Constant for a mode of start or end time specified as wall clock time. Wall clock time is standard time for the onset rule, and daylight time for the end rule.
Value: 0
Public constructors
SimpleTimeZone
SimpleTimeZone(
rawOffset: Int,
ID: String!)
Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID with no daylight saving time schedule.
Parameters | |
---|---|
rawOffset |
Int: The base time zone offset in milliseconds to GMT. |
ID |
String!: The time zone name that is given to this instance. |
SimpleTimeZone
SimpleTimeZone(
rawOffset: Int,
ID: String!,
startMonth: Int,
startDay: Int,
startDayOfWeek: Int,
startTime: Int,
endMonth: Int,
endDay: Int,
endDayOfWeek: Int,
endTime: Int)
Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time. Both 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:
<code> SimpleTimeZone(rawOffset, ID, startMonth, startDay, startDayOfWeek, startTime, SimpleTimeZone.<code><a docref="java.util.SimpleTimeZone$WALL_TIME">#WALL_TIME</a></code>, endMonth, endDay, endDayOfWeek, endTime, SimpleTimeZone.<code><a docref="java.util.SimpleTimeZone$WALL_TIME">#WALL_TIME</a></code>, 3600000) </code>
Parameters | |
---|---|
rawOffset |
Int: The given base time zone offset from GMT. |
ID |
String!: The time zone ID which is given to this object. |
startMonth |
Int: The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January). |
startDay |
Int: The day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter. |
startDayOfWeek |
Int: The daylight saving time starting day-of-week. See the class description for the special cases of this parameter. |
startTime |
Int: 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 |
Int: The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October). |
endDay |
Int: The day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter. |
endDayOfWeek |
Int: The daylight saving time ending day-of-week. See the class description for the special cases of this parameter. |
endTime |
Int: The daylight saving ending time in local wall clock time, (in milliseconds within the day) which is local daylight time in this case. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the month, day, dayOfWeek, or time parameters are out of range for the start or end rule |
SimpleTimeZone
SimpleTimeZone(
rawOffset: Int,
ID: String!,
startMonth: Int,
startDay: Int,
startDayOfWeek: Int,
startTime: Int,
endMonth: Int,
endDay: Int,
endDayOfWeek: Int,
endTime: Int,
dstSavings: Int)
Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time. Both startTime
and endTime
are assumed to be represented in the wall clock time. This constructor is equivalent to:
<code> SimpleTimeZone(rawOffset, ID, startMonth, startDay, startDayOfWeek, startTime, SimpleTimeZone.<code><a docref="java.util.SimpleTimeZone$WALL_TIME">#WALL_TIME</a></code>, endMonth, endDay, endDayOfWeek, endTime, SimpleTimeZone.<code><a docref="java.util.SimpleTimeZone$WALL_TIME">#WALL_TIME</a></code>, dstSavings) </code>
Parameters | |
---|---|
rawOffset |
Int: The given base time zone offset from GMT. |
ID |
String!: The time zone ID which is given to this object. |
startMonth |
Int: The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January). |
startDay |
Int: The day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter. |
startDayOfWeek |
Int: The daylight saving time starting day-of-week. See the class description for the special cases of this parameter. |
startTime |
Int: The daylight saving time starting time in local wall clock time, which is local standard time in this case. |
endMonth |
Int: The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October). |
endDay |
Int: The day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter. |
endDayOfWeek |
Int: The daylight saving time ending day-of-week. See the class description for the special cases of this parameter. |
endTime |
Int: The daylight saving ending time in local wall clock time, which is local daylight time in this case. |
dstSavings |
Int: The amount of time in milliseconds saved during daylight saving time. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the month, day, dayOfWeek, or time parameters are out of range for the start or end rule |
SimpleTimeZone
SimpleTimeZone(
rawOffset: Int,
ID: String!,
startMonth: Int,
startDay: Int,
startDayOfWeek: Int,
startTime: Int,
startTimeMode: Int,
endMonth: Int,
endDay: Int,
endDayOfWeek: Int,
endTime: Int,
endTimeMode: Int,
dstSavings: Int)
Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time. This constructor takes the full set of the start and end rules parameters, including modes of startTime
and endTime
. The mode specifies either wall
or standard time
or UTC
.
Parameters | |
---|---|
rawOffset |
Int: The given base time zone offset from GMT. |
ID |
String!: The time zone ID which is given to this object. |
startMonth |
Int: The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January). |
startDay |
Int: The day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter. |
startDayOfWeek |
Int: The daylight saving time starting day-of-week. See the class description for the special cases of this parameter. |
startTime |
Int: The daylight saving time starting time in the time mode specified by startTimeMode . |
startTimeMode |
Int: The mode of the start time specified by startTime. |
endMonth |
Int: The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October). |
endDay |
Int: The day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter. |
endDayOfWeek |
Int: The daylight saving time ending day-of-week. See the class description for the special cases of this parameter. |
endTime |
Int: The daylight saving ending time in time mode specified by endTimeMode . |
endTimeMode |
Int: The mode of the end time specified by endTime |
dstSavings |
Int: The amount of time in milliseconds saved during daylight saving time. |
Exceptions | |
---|---|
java.lang.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. |
See Also
Public methods
clone
open fun clone(): Any
Returns a clone of this SimpleTimeZone
instance.
Return | |
---|---|
Any |
a clone of this instance. |
Exceptions | |
---|---|
java.lang.CloneNotSupportedException |
if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned. |
equals
open fun equals(other: Any?): Boolean
Compares the equality of two SimpleTimeZone
objects.
Parameters | |
---|---|
obj |
The SimpleTimeZone object to be compared with. |
Return | |
---|---|
Boolean |
True if the given obj is the same as this SimpleTimeZone object; false otherwise. |
getDSTSavings
open fun getDSTSavings(): Int
Returns the amount of time in milliseconds that the clock is advanced during daylight saving time.
Return | |
---|---|
Int |
the number of milliseconds the time is advanced with respect to standard time when the daylight saving rules are in effect, or 0 (zero) if this time zone doesn't observe daylight saving time. |
See Also
getOffset
open fun getOffset(date: Long): Int
Returns the offset of this time zone from UTC at the given time. If daylight saving time is in effect at the given time, the offset value is adjusted with the amount of daylight saving.
Parameters | |
---|---|
date |
Long: the time at which the time zone offset is found |
Return | |
---|---|
Int |
the amount of time in milliseconds to add to UTC to get local time. |
getOffset
open fun getOffset(
era: Int,
year: Int,
month: Int,
day: Int,
dayOfWeek: Int,
millis: Int
): Int
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. This method assumes that the start and end month are distinct. It also uses a default 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.
Parameters | |
---|---|
era |
Int: The era of the given date. |
year |
Int: The year in the given date. |
month |
Int: The month in the given date. Month is 0-based. e.g., 0 for January. |
day |
Int: The day-in-month of the given date. |
dayOfWeek |
Int: The day-of-week of the given date. |
milliseconds |
the milliseconds in day in standard local time. |
millis |
Int: The milliseconds in day in standard local time. |
Return | |
---|---|
Int |
The milliseconds to add to UTC to get local time. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
the era , month , day , dayOfWeek , or millis parameters are out of range |
getRawOffset
open fun getRawOffset(): Int
Gets the GMT offset for this time zone.
Return | |
---|---|
Int |
the GMT offset value in milliseconds |
See Also
hasSameRules
open fun hasSameRules(other: TimeZone!): Boolean
Returns true
if this zone has the same rules and offset as another zone.
Parameters | |
---|---|
other |
TimeZone!: the TimeZone object to be compared with |
Return | |
---|---|
Boolean |
true if the given zone is a SimpleTimeZone and has the same rules and offset as this one |
hashCode
open fun hashCode(): Int
Generates the hash code for the SimpleDateFormat object.
Return | |
---|---|
Int |
the hash code for this object |
inDaylightTime
open fun inDaylightTime(date: Date!): Boolean
Queries if the given date is in daylight saving time.
Parameters | |
---|---|
date |
Date!: the given Date. |
Return | |
---|---|
Boolean |
true if daylight saving time is in effective at the given date; false otherwise. |
observesDaylightTime
open fun observesDaylightTime(): Boolean
Returns true
if this SimpleTimeZone
observes Daylight Saving Time. This method is equivalent to useDaylightTime()
.
Return | |
---|---|
Boolean |
true if this SimpleTimeZone observes Daylight Saving Time; false otherwise. |
setDSTSavings
open fun setDSTSavings(millisSavedDuringDST: Int): Unit
Sets the amount of time in milliseconds that the clock is advanced during daylight saving time.
Parameters | |
---|---|
millisSavedDuringDST |
Int: 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). |
See Also
setEndRule
open fun setEndRule(
endMonth: Int,
endDay: Int,
endDayOfWeek: Int,
endTime: Int
): Unit
Sets the daylight saving time end rule. For example, if daylight saving time ends on the last Sunday in October at 2 am in wall clock time, you can set the end rule by calling: setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000);
Parameters | |
---|---|
endMonth |
Int: The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October). |
endDay |
Int: The day of the month on which the daylight saving time ends. See the class description for the special cases of this parameter. |
endDayOfWeek |
Int: The daylight saving time ending day-of-week. See the class description for the special cases of this parameter. |
endTime |
Int: The daylight saving ending time in local wall clock time, (in milliseconds within the day) which is local daylight time in this case. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the endMonth , endDay , endDayOfWeek , or endTime parameters are out of range |
setEndRule
open fun setEndRule(
endMonth: Int,
endDay: Int,
endTime: Int
): Unit
Sets the daylight saving time end rule to a fixed date within a month. This method is equivalent to:
<code>setEndRule(endMonth, endDay, 0, endTime)</code>
Parameters | |
---|---|
endMonth |
Int: The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October). |
endDay |
Int: The day of the month on which the daylight saving time ends. |
endTime |
Int: The daylight saving ending time in local wall clock time, (in milliseconds within the day) which is local daylight time in this case. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
the endMonth , endDay , or endTime parameters are out of range |
setEndRule
open fun setEndRule(
endMonth: Int,
endDay: Int,
endDayOfWeek: Int,
endTime: Int,
after: Boolean
): Unit
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.
Parameters | |
---|---|
endMonth |
Int: The daylight saving time ending month. Month is a MONTH field value (0-based. e.g., 9 for October). |
endDay |
Int: The day of the month on which the daylight saving time ends. |
endDayOfWeek |
Int: The daylight saving time ending day-of-week. |
endTime |
Int: The daylight saving ending time in local wall clock time, (in milliseconds within the day) which is local daylight time in this case. |
after |
Boolean: 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. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
the endMonth , endDay , endDayOfWeek , or endTime parameters are out of range |
setRawOffset
open fun setRawOffset(offsetMillis: Int): Unit
Sets the base time zone offset to GMT. This is the offset to add to UTC to get local time.
Parameters | |
---|---|
offsetMillis |
Int: the given base time zone offset to GMT. |
See Also
setStartRule
open fun setStartRule(
startMonth: Int,
startDay: Int,
startDayOfWeek: Int,
startTime: Int
): Unit
Sets the daylight saving time start rule. For example, if daylight saving time starts on the first Sunday in April at 2 am in local wall clock time, you can set the start rule by calling:
<code>setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2*60*60*1000);</code>
Parameters | |
---|---|
startMonth |
Int: The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January). |
startDay |
Int: The day of the month on which the daylight saving time starts. See the class description for the special cases of this parameter. |
startDayOfWeek |
Int: The daylight saving time starting day-of-week. See the class description for the special cases of this parameter. |
startTime |
Int: The daylight saving time starting time in local wall clock time, which is local standard time in this case. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the startMonth , startDay , startDayOfWeek , or startTime parameters are out of range |
setStartRule
open fun setStartRule(
startMonth: Int,
startDay: Int,
startTime: Int
): Unit
Sets the daylight saving time start rule to a fixed date within a month. This method is equivalent to:
<code>setStartRule(startMonth, startDay, 0, startTime)</code>
Parameters | |
---|---|
startMonth |
Int: The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January). |
startDay |
Int: The day of the month on which the daylight saving time starts. |
startTime |
Int: 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. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the startMonth , startDayOfMonth , or startTime parameters are out of range |
setStartRule
open fun setStartRule(
startMonth: Int,
startDay: Int,
startDayOfWeek: Int,
startTime: Int,
after: Boolean
): Unit
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.
Parameters | |
---|---|
startMonth |
Int: The daylight saving time starting month. Month is a MONTH field value (0-based. e.g., 0 for January). |
startDay |
Int: The day of the month on which the daylight saving time starts. |
startDayOfWeek |
Int: The daylight saving time starting day-of-week. |
startTime |
Int: The daylight saving time starting time in local wall clock time, which is local standard time in this case. |
after |
Boolean: If true, this rule selects the first dayOfWeek on or after dayOfMonth . If false, this rule selects the last dayOfWeek on or before dayOfMonth . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the startMonth , startDay , startDayOfWeek , or startTime parameters are out of range |
setStartYear
open fun setStartYear(year: Int): Unit
Sets the daylight saving time starting year.
Parameters | |
---|---|
year |
Int: The daylight saving starting year. |
toString
open fun toString(): String
Returns a string representation of this time zone.
Return | |
---|---|
String |
a string representation of this time zone. |
useDaylightTime
open fun useDaylightTime(): Boolean
Queries if this time zone uses daylight saving time.
Return | |
---|---|
Boolean |
true if this time zone uses daylight saving time; false otherwise. |