Europe/Paris.
A ZoneId is used to identify the rules used to convert between
an Instant and a LocalDateTime.
There are two distinct types of ID:
ZoneOffset.
Calling normalized() on any ZoneId will ensure that a
fixed offset ID will be represented as a ZoneOffset.
The actual rules, describing when and how the offset changes, are defined by ZoneRules.
This class is simply an ID used to obtain the underlying rules.
This approach is taken because rules are defined by governments and change
frequently, whereas the ID is stable.
The distinction has other effects. Serializing the ZoneId will only send
the ID, whereas serializing the rules sends the entire data set.
Similarly, a comparison of two IDs only examines the ID, whereas
a comparison of two rules examines the entire data set.
The simplest type of ID is that from ZoneOffset.
This consists of 'Z' and IDs starting with '+' or '-'.
The next type of ID are offset-style IDs with some form of prefix,
such as 'GMT+2' or 'UTC+01:00'.
The recognised prefixes are 'UTC', 'GMT' and 'UT'.
The offset is the suffix and will be normalized during creation.
These IDs can be normalized to a ZoneOffset using normalized().
The third type of ID are region-based IDs. A region-based ID must be of
two or more characters, and not start with 'UTC', 'GMT', 'UT' '+' or '-'.
Region-based IDs are defined by configuration, see ZoneRulesProvider.
The configuration focuses on providing the lookup from the ID to the
underlying ZoneRules.
Time-zone rules are defined by governments and change frequently. There are a number of organizations, known here as groups, that monitor time-zone changes and collate them. The default group is the IANA Time Zone Database (TZDB). Other organizations include IATA (the airline industry body) and Microsoft.
Each group defines its own format for the region ID it provides. The TZDB group defines IDs such as 'Europe/London' or 'America/New_York'. TZDB IDs take precedence over other groups.
It is strongly recommended that the group name is included in all IDs supplied by groups other than TZDB to avoid conflicts. For example, IATA airline time-zone region IDs are typically the same as the three letter airport code. However, the airport of Utrecht has the code 'UTC', which is obviously a conflict. The recommended format for region IDs from groups other than TZDB is 'group~region'. Thus if IATA data were defined, Utrecht airport would be 'IATA~UTC'.
ZoneOffset subclass uses a dedicated format that only stores the
offset from UTC/Greenwich.
A ZoneId can be deserialized in a Java Runtime where the ID is unknown.
For example, if a server-side Java Runtime has been updated with a new zone ID, but
the client-side Java Runtime has not been updated. In this case, the ZoneId
object will exist, and can be queried using getId, equals,
hashCode, toString, getDisplayName and normalized.
However, any call to getRules will fail with ZoneRulesException.
This approach is designed to allow a ZonedDateTime to be loaded and
queried, but not modified, on a Java Runtime with incomplete time-zone information.
This is a value-based
class; programmers should treat instances that are
equal as interchangeable and should not
use instances for synchronization, or unpredictable behavior may
occur. For example, in a future release, synchronization may fail.
The equals method should be used for comparisons.
Implementation Specification
This abstract sealed class permits two implementations, both of which are immutable and
thread-safe. One implementation models region-based IDs, the other is ZoneOffset
modelling offset-based IDs. This difference is visible in serialization.
| Modifier and Type | Field and Description |
|---|---|
| private static final long | serialVersionUID
Serialization version. |
| public static final Map | SHORT_IDS
A map of zone overrides to enable the short time-zone names to be used. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true if this is equal to the other time-zone IDthe object to check, null returns false obj)Overrides java. Checks if this time-zone ID is equal to another time-zone ID. The comparison is based on the ID. |
| public static ZoneId | Returns: the zone ID, not nullthe temporal object to convert, not null temporal)Obtains an instance of |
| public static Set | Returns: a modifiable copy of the set of zone IDs, not nullGets the set of available zone IDs. |
| public String | Returns: the text value of the zone, not nullthe length of the text required, not null style, Locale the locale to use, not null locale)Gets the textual representation of the zone, such as 'British Time' or '+02:00'. |
| public abstract String | Returns: the time-zone unique ID, not nullGets the unique time-zone ID. This ID uniquely defines this object. |
| pack-priv abstract ZoneOffset | |
| public abstract ZoneRules | Returns: the rules, not nullGets the time-zone rules for this ID allowing calculations to be performed. |
| public int | Returns: a suitable hash codeOverrides java. A hash code for this time-zone ID. |
| public ZoneId | Returns: the time-zone unique ID, not nullNormalizes the time-zone ID, returning a |
| public static ZoneId | |
| public static ZoneId | |
| pack-priv static ZoneId | |
| public static ZoneId | Returns: the zone ID, not nullthe time-zone ID, not null prefix, ZoneOffset the offset, not null offset)Obtains an instance of |
| private static ZoneId | Returns: the zone ID, not nullthe time-zone ID, not null zoneId, int the length of the prefix, 2 or 3 prefixLength, boolean checkAvailable)Parse once a prefix is established. |
| private void | |
| public static ZoneId | |
| public String | Returns: a string representation of this time-zone ID, not nullOverrides java. Outputs this zone as a |
| private TemporalAccessor | Returns: a temporal equivalent to this zone, not nullConverts this zone to a |
| pack-priv abstract void | |
| private Object | Returns: the instance ofSer, not nullWrites the object using a dedicated serialized form. |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version. | |
| SHORT_IDS | back to summary |
|---|---|
| public static final Map<String, String> SHORT_IDS A map of zone overrides to enable the short time-zone names to be used.
Use of short zone IDs has been deprecated in This map contains a mapping of the IDs that is in line with TZDB 2024b and later, where 'EST', 'MST' and 'HST' map to IDs which do not include daylight savings since 1970. This mapping may change in update releases in support of new versions of TZDB. This maps as follows:
| |
| ZoneId | back to summary |
|---|---|
| pack-priv ZoneId() Constructor only accessible within the package. | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Checks if this time-zone ID is equal to another time-zone ID. The comparison is based on the ID. | |
| from | back to summary |
|---|---|
| public static ZoneId from(TemporalAccessor temporal) Obtains an instance of
This obtains a zone based on the specified temporal.
A
A
The conversion will try to obtain the zone in a way that favours region-based
zones over offset-based zones using
This method matches the signature of the functional interface
| |
| getAvailableZoneIds | back to summary |
|---|---|
| public static Set Gets the set of available zone IDs.
This set includes the string form of all available region-based IDs.
Offset-based zone IDs are not included in the returned set.
The ID can be passed to The set of zone IDs can increase over time, although in a typical application the set of IDs is fixed. Each call to this method is thread-safe. | |
| getDisplayName | back to summary |
|---|---|
| public String getDisplayName(TextStyle style, Locale locale) Gets the textual representation of the zone, such as 'British Time' or '+02:00'. This returns the textual name used to identify the time-zone ID, suitable for presentation to the user. The parameters control the style of the returned text and the locale.
If no textual mapping is found then the | |
| getId | back to summary |
|---|---|
| public abstract String getId() Gets the unique time-zone ID.
This ID uniquely defines this object.
The format of an offset based ID is defined by
| |
| getOffset | back to summary |
|---|---|
| pack-priv abstract ZoneOffset getOffset(long epochSecond) Get the effective offset for an instant at the given epochSecond. | |
| getRules | back to summary |
|---|---|
| public abstract ZoneRules getRules() Gets the time-zone rules for this ID allowing calculations to be performed. The rules provide the functionality associated with a time-zone, such as finding the offset for a given instant or local date-time.
A time-zone can be invalid if it is deserialized in a Java Runtime which
does not have the same rules loaded as the Java Runtime that stored it.
In this case, calling this method will throw a
The rules are supplied by
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. A hash code for this time-zone ID.
| |
| normalized | back to summary |
|---|---|
| public ZoneId normalized() Normalizes the time-zone ID, returning a
The returns a normalized
The normalization checks if the rules of this
| |
| of | back to summary |
|---|---|
| public static ZoneId of(String zoneId, Map<String, String> aliasMap) Obtains an instance of Many users of time-zones use short abbreviations, such as PST for 'Pacific Standard Time' and PDT for 'Pacific Daylight Time'. These abbreviations are not unique, and so cannot be used as IDs. This method allows a map of string to time-zone to be setup and reused within an application.
| |
| of | back to summary |
|---|---|
| public static ZoneId of(String zoneId) Obtains an instance of
This method parses the ID producing a Parsing matches the zone ID step by step as follows.
| |
| of | back to summary |
|---|---|
| pack-priv static ZoneId of(String zoneId, boolean checkAvailable) Parses the ID, taking a flag to indicate whether
| |
| ofOffset | back to summary |
|---|---|
| public static ZoneId ofOffset(String prefix, ZoneOffset offset) Obtains an instance of
If the prefix is "GMT", "UTC", or "UT" a
| |
| ofWithPrefix | back to summary |
|---|---|
| private static ZoneId ofWithPrefix(String zoneId, int prefixLength, boolean checkAvailable) Parse once a prefix is established.
| |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream s) throws InvalidObjectException Defend against malicious streams.
| |
| systemDefault | back to summary |
|---|---|
| public static ZoneId systemDefault() Gets the system default time-zone.
This queries
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Outputs this zone as a | |
| toTemporal | back to summary |
|---|---|
| private TemporalAccessor toTemporal() Converts this zone to a
A
The returned temporal has no supported fields, with the query method
supporting the return of the zone using
| |
| write | back to summary |
|---|---|
| pack-priv abstract void write(DataOutput out) throws IOException | |
| writeReplace | back to summary |
|---|---|
| private Object writeReplace() Writes the object using a dedicated serialized form.
| |