ZonedDate
Represents a local date in a specified timezone.
The following example demonstrates how to convert a local date to the specified timezone.
Definition
Package:@progress/kendo-date-math
Syntax:
import { ZonedDate } from '@progress/kendo-date-math';
import '@progress/kendo-date-math/tz/America/New_York';
const date = new Date('2018-03-13T00:00:00Z');
const tzDate = ZonedDate.fromLocalDate(date, 'America/New_York');
// If you run this example in GMT+0200,
// the output will be '2018-03-12T22:00:00.000Z'.
console.log(tzDate.toISOString());
The following example demonstrates how to convert between timezones.
import { ZonedDate } from '@progress/kendo-date-math';
import '@progress/kendo-date-math/tz/America/New_York';
import '@progress/kendo-date-math/tz/America/Los_Angeles';
// Note the "Z" suffix for UTC dates.
const date = new Date('2018-03-12T22:00:00Z');
const tzDate = ZonedDate.fromLocalDate(date, 'America/New_York');
const result = tzDate.toTimezone('America/Los_Angeles');
// Regardless of the browser timezone
// the output will be '2018-03-12T15:00:00.000Z'.
console.log(tzDate.toUTCDate());
Properties
timezone
string
The ID of the timezone for this instance. For example, Europe/Sofia.
timezoneOffset
number
The timezone offset in minutes at the specified date and relative to UTC.
Accessors
cachedLocalDate
Date
Returns a cached local date that denotes the exact time in the set timezone.
cachedUTCDate
Date
Returns a cached Date instance with UTC date parts that are set to the local time in the set timezone.
Methods
string
- A primitive value.
string
- A primitive value.
number
- A primitive value.
string | number
- A primitive value.
Adds the specified number of days and returns a new instance with the resulting date in the same timezone.
The number of days that will be added.
Returns:ZonedDate - The resulting date.
Adds the specified number of milliseconds and returns a new instance with the resulting date in the same timezone.
The method compensates for DST transitions and ensures that the resulting date occurs exactly after the set amount of time in the timezone.
The number of days that will be added.
Returns:ZonedDate - The resulting date.
Returns a new instance that represents the same date.
Date - A copy of the instance of the current zoned date.
Converts an existing date to a specified timezone.
If the timezone parameter is omitted, the ZonedDate defaults to the timezone of the browser. This concept is known as "floating date" because it does not represent a particular moment in time. Instead, its actual value depends on the current timezone of the browser.
The local date that represents the actual time instance.
timezonestringThe ID of the timezone that will be assumed. For example, Europe/Sofia.
ZonedDate - The date in the specified timezone.
Creates a date in a specific timezone from the UTC date parts of the supplied Date.
If the timezone parameter is omitted, the ZonedDate defaults to the timezone of the browser. This concept is known as "floating date" because it does not represent a particular moment in time. Instead, its actual value depends on the current timezone of the browser.
The ID of the timezone that will be assumed. For example, Europe/Sofia.
ZonedDate - The date in the specified timezone.
Returns a new instance of the same zoned date having its time parts set to 00:00:00.000.
ZonedDate - The same date having its time parts set to 00:00:00.000.
Returns a local date that denotes the exact time in the set timezone.
Date
Date - A local date that denotes the exact time in the set timezone.
string
- A string.
string
- A primitive value.
string
- A primitive value.
Converts the date to the specified timezone.
The timezone to which the values will be converted. For example, America/Los_Angeles.
ZonedDate - The resulting zoned date.
Returns a Date instance with UTC date parts that are set to the local time in the set timezone.
Date
Date - A Date with UTC date parts that are set to the local time in the set timezone.