ZonedDate

Represents a local date in a specified timezone.

The following example demonstrates how to convert a local date to the specified timezone.

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());

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.

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

addDays

Adds the specified number of days and returns a new instance with the resulting date in the same timezone.

Parameters

days number

The number of days that will be added.

Returns

ZonedDate ZonedDate - The resulting date.

addTime

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.

Parameters

milliseconds number

The number of days that will be added.

Returns

ZonedDate ZonedDate - The resulting date.

clone

Returns a new instance that represents the same date.

Returns

ZonedDate Date - A copy of the instance of the current zoned date.

stripTime

Returns a new instance of the same zoned date having its time parts set to 00:00:00.000.

Returns

ZonedDate ZonedDate - The same date having its time parts set to 00:00:00.000.

toLocalDate

Returns a local date that denotes the exact time in the set timezone.

import { ZonedDate } from '@progress/kendo-date-math';
import '@progress/kendo-date-math/tz/America/New_York';

// Note the "Z" suffix for UTC dates.
const date = new Date('2018-03-12T18:00:00Z');
const tzDate = ZonedDate.fromUTCDate(date, 'America/New_York');

// The local date represents the same moment in time as the ZonedDate:
// `2018-03-12T22:00:00.000Z`.
console.log(tzDate.toLocalDate().toISOString());

// The local date will apply the timezone of the browser. For example,
// `Tue Mar 13 2018 00:00:00 GMT+0200 (Eastern European Standard Time)`.
console.log(tzDate.toLocalDate().toString())

Returns

Date Date - A local date that denotes the exact time in the set timezone.

toTimezone

Converts the date to the specified timezone.

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());

Parameters

toTimezone string

The timezone to which the values will be converted. For example, America/Los_Angeles.

Returns

ZonedDate ZonedDate - The resulting zoned date.

toUTCDate

Returns a Date instance with UTC date parts that are set to the local time in the set timezone.

import { ZonedDate } from '@progress/kendo-date-math';
import '@progress/kendo-date-math/tz/America/New_York';

// Note the "Z" suffix for UTC dates.
const date = new Date('2018-03-12T18:00:00Z');
const tzDate = ZonedDate.fromUTCDate(date, 'America/New_York');

// Regardless of the browser timezone
// the output will be '2018-03-12T18:00:00.000Z'.
console.log(tzDate.toUTCDate());

Returns

Date Date - A Date with UTC date parts that are set to the local time in the set timezone.

fromLocalDate

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.

import { ZonedDate } from '@progress/kendo-date-math';
import '@progress/kendo-date-math/tz/America/New_York';

const date = new Date('2018-03-13T00:00:00');
const tzDate = ZonedDate.fromLocalDate(date, 'America/New_York');

// If you run this example in GMT+0200,
// the output will be 'Mon Mar 12 2018 18:00:00 GMT+0200 (EET)'.
console.log(tzDate.toString());

// If you run this example in UTC,
// the output will be '2018-03-12T22:00:00.000Z'.
console.log(tzDate.toISOString());

Parameters

date Date

The local date that represents the actual time instance.

timezone string

The ID of the timezone that will be assumed. For example, Europe/Sofia.

Returns

ZonedDate ZonedDate - The date in the specified timezone.

fromUTCDate

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.

import { ZonedDate } from '@progress/kendo-date-math';
import '@progress/kendo-date-math/tz/America/New_York';

// Note the "Z" suffix for UTC dates.
const date = new Date('2018-03-12T18:00:00Z');

// Alternative syntax using Date.UTC
// const date = new Date(Date.UTC(2018, 2, 12, 18, 0));

const tzDate = ZonedDate.fromUTCDate(date, 'America/New_York');

// Regardless of the browser timezone
// the output will be 'Mon Mar 12 2018 18:00:00 GMT+0200 (EET)'.
console.log(tzDate.toString());

// Regardless of the browser timezone
// the output in UTC will be '2018-03-12T22:00:00.000Z'.
console.log(tzDate.toISOString());

Parameters

utcDate Date
timezone string

The ID of the timezone that will be assumed. For example, Europe/Sofia.

Returns

ZonedDate ZonedDate - The date in the specified timezone.

 /