java.lang.Object | |
↳ | java.util.TimeZone |
Known Direct Subclasses |
TimeZone
represents a time zone offset, taking into account
daylight savings.
Typically, you get a TimeZone
using getDefault
which creates a TimeZone
based on the time zone where the
program is running. For example, for a program running in Japan,
getDefault
creates a TimeZone
object based on
Japanese Standard Time.
You can also get a TimeZone
using getTimeZone
along with a time zone ID. For instance, the time zone ID for the U.S.
Pacific Time zone is "America/Los_Angeles". So, you can get a U.S. Pacific
Time TimeZone
object with the following:
You can use theTimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
getAvailableIDs
method to iterate
through all the supported time zone IDs. You can then choose a supported ID
to get a TimeZone
. If the time zone you want is not
represented by one of the supported IDs, then you can create a custom time
zone ID with the following syntax: For example, you might specify GMT+14:00 as a custom time zone ID. TheGMT[+|-]hh[[:]mm]
TimeZone
that is returned when you specify a custom
time zone ID does not include daylight savings time.
For compatibility with JDK 1.1.x, some other three-letter time zone IDs (such as "PST", "CTT", "AST") are also supported. However, their use is deprecated because the same abbreviation is often used for multiple time zones (for example, "CST" could be U.S. "Central Standard Time" and "China Standard Time"), and the Java platform can then only recognize one of them.
Please note the type returned by factory methods, i.e. getDefault()
and getTimeZone(String)
, is implementation dependent, so it may
introduce serialization incompatibility issues between different
implementations. Android returns instances of SimpleTimeZone
so that
the bytes serialized by Android can be deserialized successfully on other
implementations, but the reverse compatibility cannot be guaranteed.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | LONG | The LONG display name style. | |||||||||
int | SHORT | The SHORT display name style. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new instance of this class.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns a new
TimeZone with the same ID, rawOffset and daylight savings
time rules as this TimeZone . | |||||||||||
Gets the available time zone IDs.
| |||||||||||
Gets the available time zone IDs which match the specified offset from
GMT.
| |||||||||||
Gets the daylight savings offset in milliseconds for this
TimeZone . | |||||||||||
Gets the default time zone.
| |||||||||||
Gets the LONG name for this
TimeZone for the default Locale in standard
time. | |||||||||||
Gets the specified style of name (
LONG or SHORT ) for this TimeZone for
the default Locale in either standard or daylight time as specified. | |||||||||||
Gets the LONG name for this
TimeZone for the specified Locale in standard
time. | |||||||||||
Gets the specified style of name (
LONG or SHORT ) for this TimeZone for
the specified Locale in either standard or daylight time as specified. | |||||||||||
Gets the ID of this
TimeZone . | |||||||||||
Gets the offset from GMT of this
TimeZone for the specified date and
time. | |||||||||||
Gets the offset from GMT of this
TimeZone for the specified date. | |||||||||||
Gets the offset for standard time from GMT for this
TimeZone . | |||||||||||
Gets the
TimeZone with the specified ID. | |||||||||||
Returns whether the specified
TimeZone has the same raw offset as this
TimeZone . | |||||||||||
Returns whether the specified
Date is in the daylight savings time period for
this TimeZone . | |||||||||||
Sets the default time zone.
| |||||||||||
Sets the ID of this
TimeZone . | |||||||||||
Sets the offset for standard time from GMT for this
TimeZone . | |||||||||||
Returns whether this
TimeZone has a daylight savings time period. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
The LONG display name style.
The SHORT display name style.
Returns a new TimeZone
with the same ID, rawOffset
and daylight savings
time rules as this TimeZone
.
TimeZone
.Gets the available time zone IDs. Any one of these IDs can be passed to
get()
to create the corresponding TimeZone
instance.
Gets the available time zone IDs which match the specified offset from
GMT. Any one of these IDs can be passed to get()
to create the corresponding
TimeZone
instance.
offset | the offset from GMT in milliseconds. |
---|
Gets the daylight savings offset in milliseconds for this TimeZone
.
This implementation returns 3600000 (1 hour), or 0 if the time zone does not observe daylight savings.
Subclasses may override to return daylight savings values other than 1 hour.
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.
TimeZone
observes daylight savings, zero otherwise.
Gets the default time zone.
Gets the LONG name for this TimeZone
for the default Locale
in standard
time. If the name is not available, the result is in the format
GMT[+-]hh:mm
.
TimeZone
name.
Gets the specified style of name (LONG
or SHORT
) for this TimeZone
for
the default Locale
in either standard or daylight time as specified. If
the name is not available, the result is in the format GMT[+-]hh:mm
.
daylightTime | true for daylight time, false for standard
time. |
---|---|
style | either LONG or SHORT . |
TimeZone
name.
Gets the LONG name for this TimeZone
for the specified Locale
in standard
time. If the name is not available, the result is in the format
GMT[+-]hh:mm
.
locale | the Locale . |
---|
TimeZone
name.
Gets the specified style of name (LONG
or SHORT
) for this TimeZone
for
the specified Locale
in either standard or daylight time as specified. If
the name is not available, the result is in the format GMT[+-]hh:mm
.
daylightTime | true for daylight time, false for standard
time. |
---|---|
style | either LONG or SHORT. |
locale | either LONG or SHORT . |
TimeZone
name.
Gets the ID of this TimeZone
.
Gets the offset from GMT of this TimeZone
for the specified date and
time. The offset includes daylight savings time if the specified date and
time are within the daylight savings time period.
era | the GregorianCalendar era, either GregorianCalendar.BC or
GregorianCalendar.AD . |
---|---|
year | the year. |
month | the Calendar month. |
day | the day of the month. |
dayOfWeek | the Calendar day of the week. |
time | the time of day in milliseconds. |
Gets the offset from GMT of this TimeZone
for the specified date. The
offset includes daylight savings time if the specified date is within the
daylight savings time period.
time | the date in milliseconds since January 1, 1970 00:00:00 GMT |
---|
Gets the offset for standard time from GMT for this TimeZone
.
Gets the TimeZone
with the specified ID.
name | a time zone string ID. |
---|
TimeZone
with the specified ID or null if no TimeZone
with
the specified ID exists.
Returns whether the specified TimeZone
has the same raw offset as this
TimeZone
.
zone | a TimeZone . |
---|
true
when the TimeZone
have the same raw offset, false
otherwise.
Returns whether the specified Date
is in the daylight savings time period for
this TimeZone
.
time | a Date . |
---|
true
when the Date
is in the daylight savings time period, false
otherwise.
Sets the default time zone. If passed null
, then the next
time getDefault()
is called, the default time zone will be
determined. This behavior is slightly different than the canonical
description of this method, but it follows the spirit of it.
timezone | a TimeZone object.
|
---|
Sets the ID of this TimeZone
.
name | a string which is the time zone ID. |
---|
Sets the offset for standard time from GMT for this TimeZone
.
offset | the offset from GMT in milliseconds. |
---|
Returns whether this TimeZone
has a daylight savings time period.
If this method returns true, that only tells you that this
TimeZone
sometimes observes daylight savings. You need to call
inDaylightTime
to find out whether daylight savings is in effect.
More specifically, this method returns true to indicate that there's at least one known future transition to or from daylight savings. This means that, say, Taiwan will return false because its historical use of daylight savings doesn't count. A hypothetical country that has never observed daylight savings before but plans to start next year would return true.
true
if this TimeZone
has a daylight savings time period, false
otherwise.