Home Reference Source
public class | source

ZoneId

Static Method Summary

Static Public Methods
public static

Obtains an instance of ZoneId from a temporal object.

public static

getAvailableZoneIds(): string[]

Gets the set of available zone IDs.

public static

of(zoneId: string): ZoneId

Obtains an instance of ZoneId from an ID ensuring that the ID is valid and available for use.

public static

ofOffset(prefix: string, offset: ZoneOffset): ZoneId

Obtains an instance of ZoneId wrapping an offset.

public static

Gets the system default time-zone.

Method Summary

Public Methods
public

equals(other: *): boolean

Checks if this time-zone ID is equal to another time-zone ID.

public

hashCode(): number

A hash code for this time-zone ID.

public

id(): String

Gets the unique time-zone ID.

public

Normalizes the time-zone ID, returning a ZoneOffset where possible.

public

Gets the time-zone rules for this ID allowing calculations to be performed.

public

toJSON(): string

toJSON() use by JSON.stringify delegates to toString()

public

toString(): string

Outputs this zone as a string, using the ID.

Static Public Methods

public static from(temporal: TemporalAccessor): ZoneId source

Obtains an instance of ZoneId from a temporal object.

A TemporalAccessor represents some form of date and time information. This factory converts the arbitrary temporal object to an instance of ZoneId.

The conversion will try to obtain the zone in a way that favours region-based zones over offset-based zones using TemporalQueries#zone.

This method matches the signature of the functional interface TemporalQuery allowing it to be used in queries via method reference, ZoneId::from.

Params:

NameTypeAttributeDescription
temporal TemporalAccessor
  • nullable: false

the temporal object to convert, not null

Return:

ZoneId

the zone ID, not null

Throw:

*

DateTimeException if unable to convert to a ZoneId

public static getAvailableZoneIds(): string[] source

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 of to create a ZoneId.

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.

Return:

string[]

a modifiable copy of the set of zone IDs, not null

public static of(zoneId: string): ZoneId source

Obtains an instance of ZoneId from an ID ensuring that the ID is valid and available for use.

This method parses the ID producing a ZoneId or ZoneOffset. A ZoneOffset is returned if the ID is 'Z', or starts with '+' or '-'. The result will always be a valid ID for which ZoneRules can be obtained.

Parsing matches the zone ID step by step as follows.

  • If the zone ID equals 'Z', the result is ZoneOffset.UTC.
  • If the zone ID consists of a single letter, the zone ID is invalid and DateTimeException is thrown.
  • If the zone ID starts with '+' or '-', the ID is parsed as a ZoneOffset using ZoneOffset#of.
  • If the zone ID equals 'GMT', 'UTC' or 'UT' then the result is a ZoneId with the same ID and rules equivalent to ZoneOffset.UTC.
  • If the zone ID starts with 'UTC+', 'UTC-', 'GMT+', 'GMT-', 'UT+' or 'UT-' then the ID is a prefixed offset-based ID. The ID is split in two, with a two or three letter prefix and a suffix starting with the sign. The suffix is parsed as a ZoneOffset. The result will be a ZoneId with the specified UTC/GMT/UT prefix and the normalized offset ID as per ZoneOffset#getId. The rules of the returned ZoneId will be equivalent to the parsed ZoneOffset.
  • All other IDs are parsed as region-based zone IDs. Region IDs must match the regular expression [A-Za-z][A-Za-z0-9~/._+-]+, otherwise a DateTimeException is thrown. If the zone ID is not in the configured set of IDs, ZoneRulesException is thrown. The detailed format of the region ID depends on the group supplying the data. The default set of data is supplied by the IANA Time Zone Database (TZDB). This has region IDs of the form '{area}/{city}', such as 'Europe/Paris' or 'America/New_York'. This is compatible with most IDs from java.util.TimeZone.

Params:

NameTypeAttributeDescription
zoneId string

the time-zone ID, not null

Return:

ZoneId

the zone ID, not null

Throw:

*

DateTimeException if the zone ID has an invalid format

*

ZoneRulesException if the zone ID is a region ID that cannot be found

public static ofOffset(prefix: string, offset: ZoneOffset): ZoneId source

Obtains an instance of ZoneId wrapping an offset.

If the prefix is 'GMT', 'UTC', or 'UT' a ZoneId with the prefix and the non-zero offset is returned. If the prefix is empty '' the ZoneOffset is returned.

Params:

NameTypeAttributeDescription
prefix string

the time-zone ID, not null

offset ZoneOffset

the offset, not null

Return:

ZoneId

the zone ID, not null

Throw:

*

IllegalArgumentException if the prefix is not one of 'GMT', 'UTC', or 'UT', or ''

public static systemDefault(): ZoneId source

Gets the system default time-zone.

Return:

ZoneId

the zone ID, not null

Public Methods

public equals(other: *): boolean source

Checks if this time-zone ID is equal to another time-zone ID.

The comparison is based on the ID.

Params:

NameTypeAttributeDescription
other *

the object to check, null returns false

Return:

boolean

true if this is equal to the other time-zone ID

public hashCode(): number source

A hash code for this time-zone ID.

Return:

number

a suitable hash code

public id(): String source

Gets the unique time-zone ID.

This ID uniquely defines this object. The format of an offset based ID is defined by ZoneOffset#getId.

Return:

String

the time-zone unique ID, not null

public normalized(): ZoneId source

Normalizes the time-zone ID, returning a ZoneOffset where possible.

The returns a normalized ZoneId that can be used in place of this ID. The result will have ZoneRules equivalent to those returned by this object, however the ID returned by getId may be different.

The normalization checks if the rules of this ZoneId have a fixed offset. If they do, then the ZoneOffset equal to that offset is returned. Otherwise this is returned.

Return:

ZoneId

the time-zone unique ID, not null

public rules(): ZoneRules source

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 ZoneRulesException.

The rules are supplied by ZoneRulesProvider. An advanced provider may support dynamic updates to the rules without restarting the Java Runtime. If so, then the result of this method may change over time. Each individual call will be still remain thread-safe.

ZoneOffset will always return a set of rules where the offset never changes.

Return:

ZoneRules (nullable: false)

the rules, not null

Throw:

*

ZoneRulesException if no rules are available for this ID

public toJSON(): string source

toJSON() use by JSON.stringify delegates to toString()

Return:

string

public toString(): string source

Outputs this zone as a string, using the ID.

Return:

string

a string representation of this time-zone ID, not null