Skip to main content
Version: 2.0.0

Class: abstract TimeZone

The abstract TimeZone class is a class that represents time zones, and is helpful when doing calendar arithmetics across time zones. It is used in conjunction with the DateTime, Time, and LocalDate classes.

Properties

displayName

displayName: string

This is the display name of the time zone.

Example

const timeZone = TimeZone.of('America/New_York');
// Returns the TimeZone instance for the time zone with the ID 'America/New_York'
timeZone.displayName; // Returns "Eastern Time"

id

id: string

This is the unique identifier of the time zone.

Example

const timeZone = TimeZone.of('America/New_York');
// Returns the TimeZone instance for the time zone with the ID 'America/New_York'
timeZone.id; // Returns "America/New_York"

UTC

static UTC: TimeZone

Get the UTC time zone

Returns

Example

const timeZone = TimeZone.UTC();
// Returns the UTC time zone
timeZone.displayName; // Returns "Coordinated Universal Time"
timeZone.id; // Returns "UTC"

Methods

of()

static of(zoneId): TimeZone

Get the displayName and id and id of the time zone

Parameters

zoneId

string

The long name (!) of the time zone. You can find a good list of all available time zones here.

Returns

TimeZone

Example

const timeZone = TimeZone.of('America/New_York');
// Returns the TimeZone instance for the time zone with the ID 'America/New_York'
timeZone.displayName; // Returns "Eastern Time"
timeZone.id; // Returns "America/New_York"

systemDefault()

static systemDefault(): TimeZone

Get the system default time zone

Returns

TimeZone

The system default time zone

Example

const timeZone = TimeZone.systemDefault();
// Returns the system default time zone
timeZone.displayName; // Returns the display name of the system default time zone, e.g. "Eastern Time"
timeZone.id; // Returns the ID of the system default time zone, e.g. "America/New_York"