TimeZone
represents a time zone offset, and also figures out 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:
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 a custom time zone ID can be specified to
produce a TimeZone. The syntax of a custom time zone ID is:
Hours must be between 0 to 23 and Minutes/Seconds must be between 00 to 59. For example, "GMT+10" and "GMT+0010" mean ten hours and ten minutes ahead of GMT, respectively.CustomID:GMT
Sign Hours:
Minutes:
SecondsGMT
Sign Hours:
MinutesGMT
Sign Hours MinutesGMT
Sign Hours Sign: one of+ -
Hours: Digit Digit Digit Minutes: Digit Digit Seconds: Digit Digit Digit: one of0 1 2 3 4 5 6 7 8 9
The format is locale independent and digits must be taken from the
Basic Latin block of the Unicode standard. No daylight saving time
transition schedule can be specified with a custom time zone ID. If
the specified string doesn't match the syntax, "GMT"
is used.
When creating a TimeZone
, the specified custom time
zone ID is normalized in the following syntax:
For example, TimeZone.getTimeZone("GMT-8").getID() returns "GMT-08:00". ColonSeconds part only appears if the seconds value is non-zero.NormalizedCustomID:GMT
Sign TwoDigitHours:
Minutes [ColonSeconds] Sign: one of+ -
TwoDigitHours: Digit Digit Minutes: Digit Digit ColonSeconds::
Digit Digit Digit: one of0 1 2 3 4 5 6 7 8 9
java.time.ZoneId#SHORT_IDS
.
Calendar
, GregorianCalendar
, SimpleTimeZone
Modifier and Type | Field and Description |
---|---|
private static volatile TimeZone | |
pack-priv static final String | |
private static final int | |
private String | ID
The string identifier of this |
public static final int | LONG
A style specifier for |
pack-priv static final TimeZone | NO_TIMEZONE
The null constant as a TimeZone. |
private static final int | |
private static final int | |
private static final int | |
pack-priv static final long | |
public static final int | SHORT
A style specifier for |
private transient ZoneId |
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
public Object | Returns: a clone of thisTimeZone Overrides java. Creates a copy of this |
public static synchronized String[] | Returns: an array of IDs, where the time zone for that ID has the specified GMT offset. For example, "America/Phoenix" and "America/Denver" both have GMT-07:00, but differ in daylight saving behavior.the given time zone GMT offset in milliseconds. rawOffset)Gets the available IDs according to the given time zone offset in milliseconds. |
public static synchronized String[] | |
public static TimeZone | |
pack-priv static TimeZone | |
public final String | Returns: the human-readable name of this time zone in the default locale.Returns a long standard time name of this |
public final String | Returns: the human-readable name of this time zone in the given locale.the locale in which to supply the display name. locale)Returns a long standard time name of this |
public final String | Returns: the human-readable name of this time zone in the default locale.true specifying a Daylight Saving Time name, or
false specifying a Standard Time nameReturns a name in the specified |
public String | Returns: the human-readable name of this time zone in the given locale.true specifying a Daylight Saving Time name, or
false specifying a Standard Time namethe locale in which to supply the display name. locale)Returns a name in the specified |
private static String[] | |
public int | Returns: the amount of saving time in millisecondsReturns the amount of time to be added to local standard time to get local wall clock time. |
public String | |
public abstract int | Returns: the offset in milliseconds to add to GMT to get local time.the era of the given date. era, int the year in the given date. year, int the month in the given date.
Month is 0-based. e.g., 0 for January. month, int the day-in-month of the given date. day, int the day-of-week of the given date. dayOfWeek, int the milliseconds in day in standard
local time. milliseconds)Gets the time zone offset, for current date, modified in case of daylight savings. |
public int | Returns: the amount of time in milliseconds to add to UTC to get local time.the date represented in milliseconds since January 1, 1970 00:00:00 GMT date)Returns the offset of this time zone from UTC at the specified date. |
pack-priv int | Returns: the total amount of the raw GMT offset and daylight saving at the specified date.the milliseconds (since January 1, 1970,
00:00:00.000 GMT) at which the time zone offset and daylight
saving amount are found date, int[] an array of int where the raw GMT offset
(offset[0]) and daylight saving amount (offset[1]) are stored,
or null if those values are not needed. The method assumes that
the length of the given array is two or larger. offsets)Gets the raw GMT offset and the amount of daylight saving of this time zone at the given time. |
public abstract int | Returns: the amount of raw offset time in milliseconds to add to UTC.Returns the amount of time in milliseconds to add to UTC to get standard time in this time zone. |
private static native String | |
private static native String | |
public static synchronized TimeZone | Returns: the specifiedTimeZone , or the GMT zone if the given ID
cannot be understood.the ID for a ID)TimeZone , either an abbreviation
such as "PST", a full name such as "America/Los_Angeles", or a custom
ID such as "GMT-8:00". Note that the support of abbreviations is
for JDK 1.1.x compatibility only and full names should be used.Gets the |
public static TimeZone | Returns: the specifiedTimeZone , or the GMT zone if the given ID
cannot be understood.a zoneId)ZoneId from which the time zone ID is obtainedGets the |
private static TimeZone | |
public boolean | Returns: true if the other zone is not null and is the same as this one, with the possible exception of the IDthe other)TimeZone object to be compared withReturns true if this zone has the same rule and offset as another zone. |
public abstract boolean | Returns: true if the given date is in Daylight Saving Time,
false , otherwise.the given Date. date)Queries if the given |
public boolean | Returns: true if this TimeZone is currently in
Daylight Saving Time, or if a transition from Standard Time to
Daylight Saving Time occurs at any future time; false
otherwise.Returns |
private static final TimeZone | Returns: a newly created TimeZone with the given offset and no daylight saving time, or null if the id cannot be parsed.a string of the custom ID form. id)Parses a custom time zone identifier and returns a corresponding zone. |
public static void | setDefault(TimeZone
the new default zone)TimeZone , or nullSets the |
private static synchronized TimeZone | |
public void | |
public abstract void | setRawOffset(int
the given base time zone offset to GMT. offsetMillis)Sets the base time zone offset to GMT. |
public ZoneId | Returns: aZoneId representing the same time zone as this
TimeZone Converts this |
private ZoneId | |
public abstract boolean | Returns: true if this TimeZone uses Daylight Saving Time,
false , otherwise.Queries if this |
defaultTimeZone | back to summary |
---|---|
private static volatile TimeZone defaultTimeZone |
GMT_ID | back to summary |
---|---|
pack-priv static final String GMT_ID |
GMT_ID_LENGTH | back to summary |
---|---|
private static final int GMT_ID_LENGTH |
ID | back to summary |
---|---|
private String ID The string identifier of this |
LONG | back to summary |
---|---|
public static final int LONG A style specifier for
|
NO_TIMEZONE | back to summary |
---|---|
pack-priv static final TimeZone NO_TIMEZONE The null constant as a TimeZone. |
ONE_DAY | back to summary |
---|---|
private static final int ONE_DAY |
ONE_HOUR | back to summary |
---|---|
private static final int ONE_HOUR |
ONE_MINUTE | back to summary |
---|---|
private static final int ONE_MINUTE |
serialVersionUID | back to summary |
---|---|
pack-priv static final long serialVersionUID
|
SHORT | back to summary |
---|---|
public static final int SHORT A style specifier for
|
zoneId | back to summary |
---|---|
private transient ZoneId zoneId Cached |
TimeZone | back to summary |
---|---|
public TimeZone() Sole constructor. (For invocation by subclass constructors, typically implicit.) |
clone | back to summary |
---|---|
public Object clone() Overrides java. Creates a copy of this
|
getAvailableIDs | back to summary |
---|---|
public static synchronized String[] getAvailableIDs(int rawOffset) Gets the available IDs according to the given time zone offset in milliseconds.
|
getAvailableIDs | back to summary |
---|---|
public static synchronized String[] getAvailableIDs() Gets all the available IDs supported.
|
getDefault | back to summary |
---|---|
public static TimeZone getDefault() Gets the default
The default
|
getDefaultRef | back to summary |
---|---|
pack-priv static TimeZone getDefaultRef() Returns the reference to the default TimeZone object. This method doesn't create a clone. |
getDisplayName | back to summary |
---|---|
public final String getDisplayName() Returns a long standard time name of this This method is equivalent to:
|
getDisplayName | back to summary |
---|---|
public final String getDisplayName(Locale locale) Returns a long standard time name of this This method is equivalent to:
|
getDisplayName | back to summary |
---|---|
public final String getDisplayName(boolean daylight, int style) Returns a name in the specified This method is equivalent to:
|
getDisplayName | back to summary |
---|---|
public String getDisplayName(boolean daylight, int style, Locale locale) Returns a name in the specified When looking up a time zone name, the default
Implementation Specification The default implementation throws an
|
getDisplayNames | back to summary |
---|---|
private static String[] getDisplayNames(String id, Locale locale) |
getDSTSavings | back to summary |
---|---|
public int getDSTSavings() Returns the amount of time to be added to local standard time to get local wall clock time. The default implementation returns 3600000 milliseconds
(i.e., one hour) if a call to If an underlying If the amount of saving time at any given time stamp is
required, construct a
|
getID | back to summary |
---|---|
public String getID() Gets the ID of this time zone.
|
getOffset | back to summary |
---|---|
public abstract int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds) Gets the time zone offset, for current date, modified in case of daylight savings. This is the offset to add to UTC to get local time.
This method returns a historically correct offset if an
underlying
|
getOffset | back to summary |
---|---|
public int getOffset(long date) Returns the offset of this time zone from UTC at the specified date. If Daylight Saving Time is in effect at the specified date, the offset value is adjusted with the amount of daylight saving. This method returns a historically correct offset value if an underlying TimeZone implementation subclass supports historical Daylight Saving Time schedule and GMT offset changes.
|
getOffsets | back to summary |
---|---|
pack-priv int getOffsets(long date, int[] offsets) Gets the raw GMT offset and the amount of daylight saving of this time zone at the given time.
|
getRawOffset | back to summary |
---|---|
public abstract int getRawOffset() Returns the amount of time in milliseconds to add to UTC to get standard time in this time zone. Because this value is not affected by daylight saving time, it is called raw offset.
If an underlying
|
getSystemGMTOffsetID | back to summary |
---|---|
private static native String getSystemGMTOffsetID() Gets the custom time zone ID based on the GMT offset of the platform. (e.g., "GMT+08:00") |
getSystemTimeZoneID | back to summary |
---|---|
private static native String getSystemTimeZoneID(String javaHome) Gets the platform defined TimeZone ID. |
getTimeZone | back to summary |
---|---|
public static synchronized TimeZone getTimeZone(String ID) Gets the
|
getTimeZone | back to summary |
---|---|
public static TimeZone getTimeZone(ZoneId zoneId) Gets the
|
getTimeZone | back to summary |
---|---|
private static TimeZone getTimeZone(String ID, boolean fallback) |
hasSameRules | back to summary |
---|---|
public boolean hasSameRules(TimeZone other) Returns true if this zone has the same rule and offset as another zone. That is, if this zone differs only in ID, if at all. Returns false if the other zone is null.
|
inDaylightTime | back to summary |
---|---|
public abstract boolean inDaylightTime(Date date) Queries if the given
|
observesDaylightTime | back to summary |
---|---|
public boolean observesDaylightTime() Returns The default implementation returns
|
parseCustomTimeZone | back to summary |
---|---|
private static final TimeZone parseCustomTimeZone(String id) Parses a custom time zone identifier and returns a corresponding zone. This method doesn't support the RFC 822 time zone format. (e.g., +hhmm)
|
setDefault | back to summary |
---|---|
public static void setDefault(TimeZone zone) Sets the
|
setDefaultZone | back to summary |
---|---|
private static synchronized TimeZone setDefaultZone() |
setID | back to summary |
---|---|
public void setID(String ID) Sets the time zone ID. This does not change any other data in the time zone object. Implementation Specification The default implementation throws a
|
setRawOffset | back to summary |
---|---|
public abstract void setRawOffset(int offsetMillis) Sets the base time zone offset to GMT. This is the offset to add to UTC to get local time.
If an underlying
|
toZoneId | back to summary |
---|---|
public ZoneId toZoneId() Converts this
|
toZoneId0 | back to summary |
---|---|
private ZoneId toZoneId0() |
useDaylightTime | back to summary |
---|---|
public abstract boolean useDaylightTime() Queries if this If an underlying
|