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 useTimeZone 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. @see Calendar @see GregorianCalendar @see SimpleTimeZone @author Mark Davis, David Goldsmith, Chen-Lieh Huang, Alan Liu @stable ICU 2.0
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 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:
MinutesGMT
Sign Hours MinutesGMT
Sign Hours Sign: one of+ -
Hours: Digit Digit Digit Minutes: 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".NormalizedCustomID:GMT
Sign TwoDigitHours:
Minutes Sign: one of+ -
TwoDigitHours: Digit Digit Minutes: Digit Digit Digit: one of0 1 2 3 4 5 6 7 8 9
Time zones are geographical regions where the same rules for time apply. The rules are defined by governments and change frequently.
There are a number of sources of time zone information available, each represented by an instance of {@link ZoneRulesGroup}. One group is provided as standard - 'TZDB' - and more can be added.
Each group defines a naming scheme for the regions of the time zone. The format of the region is specific to the group. For example, the 'TZDB' group typically use the format {area}/{city}, such as 'Europe/London'.
Each group typically produces multiple versions of their data. The format of the version is specific to the group. For example, the 'TZDB' group use the format {year}{letter}, such as '2009b'.
In combination, a unique ID is created expressing the time-zone, formed from {groupID}:{regionID}#{versionID}.
The version can be set to an empty string. This represents the "floating version". The floating version will always choose the latest applicable set of rules. Applications will probably choose to use the floating version, as it guarantees usage of the latest rules.
In addition to the group/region/version combinations, TimeZone
can represent a fixed offset. This has an empty group and version ID. It is not possible to have an invalid instance of a fixed time zone.
The purpose of capturing all this information is to handle issues when manipulating and persisting time zones. For example, consider what happens if the government of a country changed the start or end of daylight savings time. If you created and stored a date using one version of the rules, and then load it up when a new version of the rules are in force, what should happen? The date might now be invalid, for example due to a gap in the local time-line. By storing the version of the time zone rules data together with the date, it is possible to tell that the rules have changed and to process accordingly.
TimeZone
merely represents the identifier of the zone. The actual rules are provided by {@link ZoneRules}. One difference is that serializing this class only stores the reference to the zone, whereas serializing ZoneRules
stores the entire set of rules.
After deserialization, or by using the special constructor, it is possible for the time zone to represent a group/region/version combination that is unavailable. Since this class can still be loaded even when the rules cannot, the application can continue. For example, a {@link ZonedDateTime} instance could still be queried.The application might also take appropriate corrective action. For example, an application might choose to download missing rules from a central server.
TimeZone is immutable and thread-safe. @author Stephen Colebourne
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|