Skip to content

Most visited

Recently visited

navigation
Added in API level 1

SimpleTimeZone

public class SimpleTimeZone
extends TimeZone

java.lang.Object
   ↳ java.util.TimeZone
     ↳ java.util.SimpleTimeZone


SimpleTimeZone is a concrete subclass of TimeZone that represents a time zone for use with a Gregorian calendar. This class does not handle historical changes.

Use a negative value for dayOfWeekInMonth to indicate that SimpleTimeZone should count from the end of the month backwards. For example, Daylight Savings Time ends at the last (dayOfWeekInMonth = -1) Sunday in October, at 2 AM in standard time.

See also:

Summary

Constants

int STANDARD_TIME

The constant for representing a start or end time in standard local time mode, based on timezone's raw offset from GMT; does not include Daylight savings.

int UTC_TIME

The constant for representing a start or end time in GMT time mode.

int WALL_TIME

The constant for representing a start or end time in local wall clock time mode, based on timezone's adjusted offset from GMT; includes Daylight savings.

Inherited constants

From class java.util.TimeZone

Public constructors

SimpleTimeZone(int offset, String name)

Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID.

SimpleTimeZone(int offset, String name, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime)

Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and times to start and end the daylight savings time.

SimpleTimeZone(int offset, String name, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime, int daylightSavings)

Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, times to start and end the daylight savings time, and the daylight savings time difference in milliseconds.

SimpleTimeZone(int offset, String name, int startMonth, int startDay, int startDayOfWeek, int startTime, int startTimeMode, int endMonth, int endDay, int endDayOfWeek, int endTime, int endTimeMode, int daylightSavings)

Construct a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, times to start and end the daylight savings time including a mode specifier, the daylight savings time difference in milliseconds.

Public methods

Object clone()

Returns a new SimpleTimeZone with the same ID, rawOffset and daylight savings time rules as this SimpleTimeZone.

boolean equals(Object object)

Compares the specified object to this SimpleTimeZone and returns whether they are equal.

int getDSTSavings()

Returns the latest daylight savings in milliseconds for this time zone, relative to this time zone's regular UTC offset (as returned by getRawOffset()).

int getOffset(int era, int year, int month, int day, int dayOfWeek, int time)

Returns this time zone's offset in milliseconds from UTC at the specified date and time.

int getOffset(long time)

Returns the offset in milliseconds from UTC for this time zone at time.

int getRawOffset()

Returns the offset in milliseconds from UTC of this time zone's standard time.

boolean hasSameRules(TimeZone zone)

Returns true if timeZone has the same rules as this time zone.

int hashCode()

Returns an integer hash code for the receiver.

boolean inDaylightTime(Date time)

Returns true if time is in a daylight savings time period for this time zone.

void setDSTSavings(int milliseconds)

Sets the daylight savings offset in milliseconds for this SimpleTimeZone.

void setEndRule(int month, int day, int dayOfWeek, int time)

Sets the rule which specifies the end of daylight savings time.

void setEndRule(int month, int dayOfMonth, int time)

Sets the rule which specifies the end of daylight savings time.

void setEndRule(int month, int day, int dayOfWeek, int time, boolean after)

Sets the rule which specifies the end of daylight savings time.

void setRawOffset(int offset)

Sets the offset for standard time from GMT for this SimpleTimeZone.

void setStartRule(int month, int day, int dayOfWeek, int time, boolean after)

Sets the rule which specifies the start of daylight savings time.

void setStartRule(int month, int dayOfMonth, int time)

Sets the rule which specifies the start of daylight savings time.

void setStartRule(int month, int day, int dayOfWeek, int time)

Sets the rule which specifies the start of daylight savings time.

void setStartYear(int year)

Sets the starting year for daylight savings time in this SimpleTimeZone.

String toString()

Returns the string representation of this SimpleTimeZone.

boolean useDaylightTime()

Returns true if this time zone has a future transition to or from daylight savings time.

Inherited methods

From class java.util.TimeZone
From class java.lang.Object

Constants

STANDARD_TIME

Added in API level 1
int STANDARD_TIME

The constant for representing a start or end time in standard local time mode, based on timezone's raw offset from GMT; does not include Daylight savings.

Constant Value: 1 (0x00000001)

UTC_TIME

Added in API level 1
int UTC_TIME

The constant for representing a start or end time in GMT time mode.

Constant Value: 2 (0x00000002)

WALL_TIME

Added in API level 1
int WALL_TIME

The constant for representing a start or end time in local wall clock time mode, based on timezone's adjusted offset from GMT; includes Daylight savings.

Constant Value: 0 (0x00000000)

Public constructors

SimpleTimeZone

Added in API level 1
SimpleTimeZone (int offset, 
                String name)

Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID. Timezone IDs can be obtained from TimeZone.getAvailableIDs. Normally you should use TimeZone.getDefault to construct a TimeZone.

Parameters
offset int: the given base time zone offset to GMT.
name String: the time zone ID which is obtained from TimeZone.getAvailableIDs.

SimpleTimeZone

Added in API level 1
SimpleTimeZone (int offset, 
                String name, 
                int startMonth, 
                int startDay, 
                int startDayOfWeek, 
                int startTime, 
                int endMonth, 
                int endDay, 
                int endDayOfWeek, 
                int endTime)

Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and times to start and end the daylight savings time. Timezone IDs can be obtained from TimeZone.getAvailableIDs. Normally you should use TimeZone.getDefault to create a TimeZone. For a time zone that does not use daylight saving time, do not use this constructor; instead you should use SimpleTimeZone(rawOffset, ID).

By default, this constructor specifies day-of-week-in-month rules. That is, if the startDay is 1, and the startDayOfWeek is SUNDAY, then this indicates the first Sunday in the startMonth. A startDay of -1 likewise indicates the last Sunday. However, by using negative or zero values for certain parameters, other types of rules can be specified.

Day of month: To specify an exact day of the month, such as March 1, set startDayOfWeek to zero.

Day of week after day of month: To specify the first day of the week occurring on or after an exact day of the month, make the day of the week negative. For example, if startDay is 5 and startDayOfWeek is -MONDAY, this indicates the first Monday on or after the 5th day of the startMonth.

Day of week before day of month: To specify the last day of the week occurring on or before an exact day of the month, make the day of the week and the day of the month negative. For example, if startDay is -21 and startDayOfWeek is -WEDNESDAY, this indicates the last Wednesday on or before the 21st of the startMonth.

The above examples refer to the startMonth, startDay, and startDayOfWeek; the same applies for the endMonth, endDay, and endDayOfWeek.

The daylight savings time difference is set to the default value: one hour.

Parameters
offset int: the given base time zone offset to GMT.
name String: the time zone ID which is obtained from TimeZone.getAvailableIDs.
startMonth int: the daylight savings starting month. The month indexing is 0-based. eg, 0 for January.
startDay int: the daylight savings starting day-of-week-in-month. Please see the member description for an example.
startDayOfWeek int: the daylight savings starting day-of-week. Please see the member description for an example.
startTime int: the daylight savings starting time in local wall time, which is standard time in this case. Please see the member description for an example.
endMonth int: the daylight savings ending month. The month indexing is 0-based. eg, 0 for January.
endDay int: the daylight savings ending day-of-week-in-month. Please see the member description for an example.
endDayOfWeek int: the daylight savings ending day-of-week. Please see the member description for an example.
endTime int: the daylight savings ending time in local wall time, which is daylight time in this case. Please see the member description for an example.
Throws
IllegalArgumentException if the month, day, dayOfWeek, or time parameters are out of range for the start or end rule.

SimpleTimeZone

Added in API level 1
SimpleTimeZone (int offset, 
                String name, 
                int startMonth, 
                int startDay, 
                int startDayOfWeek, 
                int startTime, 
                int endMonth, 
                int endDay, 
                int endDayOfWeek, 
                int endTime, 
                int daylightSavings)

Constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, times to start and end the daylight savings time, and the daylight savings time difference in milliseconds.

Parameters
offset int: the given base time zone offset to GMT.
name String: the time zone ID which is obtained from TimeZone.getAvailableIDs.
startMonth int: the daylight savings starting month. Month is 0-based. eg, 0 for January.
startDay int: the daylight savings starting day-of-week-in-month. Please see the description of SimpleTimeZone(int, String, int, int, int, int, int, int, int, int) for an example.
startDayOfWeek int: the daylight savings starting day-of-week. Please see the description of SimpleTimeZone(int, String, int, int, int, int, int, int, int, int) for an example.
startTime int: The daylight savings starting time in local wall time, which is standard time in this case. Please see the description of SimpleTimeZone(int, String, int, int, int, int, int, int, int, int) for an example.
endMonth int: the daylight savings ending month. Month is 0-based. eg, 0 for January.
endDay int: the daylight savings ending day-of-week-in-month. Please see the description of SimpleTimeZone(int, String, int, int, int, int, int, int, int, int) for an example.
endDayOfWeek int: the daylight savings ending day-of-week. Please see the description of SimpleTimeZone(int, String, int, int, int, int, int, int, int, int) for an example.
endTime int: the daylight savings ending time in local wall time, which is daylight time in this case. Please see the description of SimpleTimeZone(int, String, int, int, int, int, int, int, int, int) for an example.
daylightSavings int: the daylight savings time difference in milliseconds.
Throws
IllegalArgumentException if the month, day, dayOfWeek, or time parameters are out of range for the start or end rule.

SimpleTimeZone

Added in API level 1
SimpleTimeZone (int offset, 
                String name, 
                int startMonth, 
                int startDay, 
                int startDayOfWeek, 
                int startTime, 
                int startTimeMode, 
                int endMonth, 
                int endDay, 
                int endDayOfWeek, 
                int endTime, 
                int endTimeMode, 
                int daylightSavings)

Construct a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, times to start and end the daylight savings time including a mode specifier, the daylight savings time difference in milliseconds. The mode specifies either WALL_TIME, STANDARD_TIME, or UTC_TIME.

Parameters
offset int: the given base time zone offset to GMT.
name String: the time zone ID which is obtained from TimeZone.getAvailableIDs.
startMonth int: the daylight savings starting month. The month indexing is 0-based. eg, 0 for January.
startDay int: the daylight savings starting day-of-week-in-month. Please see the description of SimpleTimeZone(int, String, int, int, int, int, int, int, int, int) for an example.
startDayOfWeek int: the daylight savings starting day-of-week. Please see the description of SimpleTimeZone(int, String, int, int, int, int, int, int, int, int) for an example.
startTime int: the time of day in milliseconds on which daylight savings time starts, based on the startTimeMode.
startTimeMode int: the mode (UTC, standard, or wall time) of the start time value.
endMonth int: the daylight savings ending month. The month indexing is 0-based. eg, 0 for January.
endDay int: the day of the week on which daylight savings time ends.
endDayOfWeek int: the daylight savings ending day-of-week. Please see the description of SimpleTimeZone(int, String, int, int, int, int, int, int, int, int) for an example.
endTime int: the time of day in milliseconds on which daylight savings time ends, based on the endTimeMode.
endTimeMode int: the mode (UTC, standard, or wall time) of the end time value.
daylightSavings int: the daylight savings time difference in milliseconds.
Throws
IllegalArgumentException if the month, day, dayOfWeek, or time parameters are out of range for the start or end rule.

Public methods

clone

Added in API level 1
Object clone ()

Returns a new SimpleTimeZone with the same ID, rawOffset and daylight savings time rules as this SimpleTimeZone.

Returns
Object a shallow copy of this SimpleTimeZone.

See also:

equals

Added in API level 1
boolean equals (Object object)

Compares the specified object to this SimpleTimeZone and returns whether they are equal. The object must be an instance of SimpleTimeZone and have the same internal data.

Parameters
object Object: the object to compare with this object.
Returns
boolean true if the specified object is equal to this SimpleTimeZone, false otherwise.

See also:

getDSTSavings

Added in API level 1
int getDSTSavings ()

Returns the latest daylight savings in milliseconds for this time zone, relative to this time zone's regular UTC offset (as returned by getRawOffset()).

This class returns 3600000 (1 hour) for time zones that use daylight savings time and 0 for timezones that do not, leaving it to subclasses to override this method for other daylight savings offsets. (There are time zones, such as Australia/Lord_Howe, that use other values.)

Note that this method doesn't tell you whether or not to apply the offset: you need to call inDaylightTime for the specific time you're interested in. If this method returns a non-zero offset, that only tells you that this TimeZone sometimes observes daylight savings.

Note also that this method doesn't necessarily return the value you need to apply to the time you're working with. This value can and does change over time for a given time zone.

It's highly unlikely that you should ever call this method. You probably want getOffset(int, int, int, int, int, int) instead, which tells you the offset for a specific point in time, and takes daylight savings into account for you.

Returns
int

getOffset

Added in API level 1
int getOffset (int era, 
                int year, 
                int month, 
                int day, 
                int dayOfWeek, 
                int time)

Returns this time zone's offset in milliseconds from UTC at the specified date and time. The offset includes daylight savings time if the date and time is within the daylight savings time period.

This method is intended to be used by Calendar to compute DST_OFFSET and ZONE_OFFSET. Application code should have no reason to call this method directly. Each parameter is interpreted in the same way as the corresponding Calendar field. Refer to Calendar for specific definitions of this method's parameters.

Parameters
era int
year int
month int
day int
dayOfWeek int
time int
Returns
int

getOffset

Added in API level 1
int getOffset (long time)

Returns the offset in milliseconds from UTC for this time zone at time. The offset includes daylight savings time if the specified date is within the daylight savings time period.

Parameters
time long: the date in milliseconds since January 1, 1970 00:00:00 UTC
Returns
int

getRawOffset

Added in API level 1
int getRawOffset ()

Returns the offset in milliseconds from UTC of this time zone's standard time.

Returns
int

hasSameRules

Added in API level 1
boolean hasSameRules (TimeZone zone)

Returns true if timeZone has the same rules as this time zone.

The base implementation returns true if both time zones have the same raw offset.

Parameters
zone TimeZone
Returns
boolean

hashCode

Added in API level 1
int hashCode ()

Returns an integer hash code for the receiver. Objects which are equal return the same value for this method.

Returns
int the receiver's hash.

See also:

inDaylightTime

Added in API level 1
boolean inDaylightTime (Date time)

Returns true if time is in a daylight savings time period for this time zone.

Parameters
time Date
Returns
boolean

setDSTSavings

Added in API level 1
void setDSTSavings (int milliseconds)

Sets the daylight savings offset in milliseconds for this SimpleTimeZone.

Parameters
milliseconds int: the daylight savings offset in milliseconds.

setEndRule

Added in API level 1
void setEndRule (int month, 
                int day, 
                int dayOfWeek, 
                int time)

Sets the rule which specifies the end of daylight savings time.

Parameters
month int: the Calendar month in which daylight savings time ends.
day int: the occurrence of the day of the week on which daylight savings time ends.
dayOfWeek int: the Calendar day of the week on which daylight savings time ends.
time int: the time of day in milliseconds standard time on which daylight savings time ends.

setEndRule

Added in API level 1
void setEndRule (int month, 
                int dayOfMonth, 
                int time)

Sets the rule which specifies the end of daylight savings time.

Parameters
month int: the Calendar month in which daylight savings time ends.
dayOfMonth int: the Calendar day of the month on which daylight savings time ends.
time int: the time of day in milliseconds standard time on which daylight savings time ends.

setEndRule

Added in API level 1
void setEndRule (int month, 
                int day, 
                int dayOfWeek, 
                int time, 
                boolean after)

Sets the rule which specifies the end of daylight savings time.

Parameters
month int: the Calendar month in which daylight savings time ends.
day int: the Calendar day of the month.
dayOfWeek int: the Calendar day of the week on which daylight savings time ends.
time int: the time of day in milliseconds on which daylight savings time ends.
after boolean: selects the day after or before the day of month.

setRawOffset

Added in API level 1
void setRawOffset (int offset)

Sets the offset for standard time from GMT for this SimpleTimeZone.

Parameters
offset int: the offset from GMT of standard time in milliseconds.

setStartRule

Added in API level 1
void setStartRule (int month, 
                int day, 
                int dayOfWeek, 
                int time, 
                boolean after)

Sets the rule which specifies the start of daylight savings time.

Parameters
month int: the Calendar month in which daylight savings time starts.
day int: the Calendar day of the month.
dayOfWeek int: the Calendar day of the week on which daylight savings time starts.
time int: the time of day in milliseconds on which daylight savings time starts.
after boolean: selects the day after or before the day of month.

setStartRule

Added in API level 1
void setStartRule (int month, 
                int dayOfMonth, 
                int time)

Sets the rule which specifies the start of daylight savings time.

Parameters
month int: the Calendar month in which daylight savings time starts.
dayOfMonth int: the Calendar day of the month on which daylight savings time starts.
time int: the time of day in milliseconds on which daylight savings time starts.

setStartRule

Added in API level 1
void setStartRule (int month, 
                int day, 
                int dayOfWeek, 
                int time)

Sets the rule which specifies the start of daylight savings time.

Parameters
month int: the Calendar month in which daylight savings time starts.
day int: the occurrence of the day of the week on which daylight savings time starts.
dayOfWeek int: the Calendar day of the week on which daylight savings time starts.
time int: the time of day in milliseconds on which daylight savings time starts.

setStartYear

Added in API level 1
void setStartYear (int year)

Sets the starting year for daylight savings time in this SimpleTimeZone. Years before this start year will always be in standard time.

Parameters
year int: the starting year.

toString

Added in API level 1
String toString ()

Returns the string representation of this SimpleTimeZone.

Returns
String the string representation of this SimpleTimeZone.

useDaylightTime

Added in API level 1
boolean useDaylightTime ()

Returns true if this time zone has a future transition to or from daylight savings time.

Warning: this returns false for time zones like Asia/Kuala_Lumpur that have previously used DST but do not currently. A hypothetical country that has never observed daylight savings before but plans to start next year would return true.

Warning: this returns true for time zones that use DST, even when it is not active.

Use inDaylightTime(Date) to find out whether daylight savings is in effect at a specific time.

Most applications should not use this method.

Returns
boolean
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.