TZDate is a custom date class created to handle timezones. When creating an event, the event start date or end date can be specified with TZDate, and the date and time-related values in the calendar API are returned as TZDate.
import Calendar, { TZDate } from '@toast-ui/calendar';
const calendar = new Calendar('#container');
calendar.createEvents([
{
id: '1',
calendarId: 'cal1',
title: 'event',
start: new TZDate('2022-06-01T10:00:00'), // TZDate
end: new TZDate('2022-06-01T11:00:00'), // TZDate
},
]);
console.log(calendar.getDate()); // TZDate
console.log(calendar.getEvent('1', 'cal1').start); // TZDate
- Type
new TZDate(date?: number | string | Date | TZDate)
new TZDate(year: number, monthIndex: number, day?: number, hours?: number, minutes?: number, seconds?: number, milliseconds?: number)
- Parameters
date
or individual date and time components: values representing the date and time
TZDate can be created with the following parameters.
- Without parameters: Without parameters, a TZDate instance with the date and time of creation is created.
- UNIX timestamp value
- Timestamp string
- Individual date and time components
- Date instance
- TZDate instance
Except for the TZDate instance, the rest of the parameters are the same as the Date()
constructor parameters, so refer to Date()
constructor parameters for details.
import { TZDate } from '@toast-ui/calendar';
const now = new TZDate(); // no parameters
const date = new TZDate(1654052400000); // UNIX timestamp value
const date1 = new TZDate('2022-06-01T12:00:00'); // timestamp string
const date2 = new TZDate(2022, 5, 1, 12, 0, 0, 0); // individual date and time components const now1 = new TZDate(new Date()); // Date instance
const now2 = new TZDate(new TZDate()); // TZDate instance
💡 Click on a method to see more detailed explanations and usage examples.
Method | Description |
---|---|
toString | Returns the date and time of the TZDate instance as a string. |
toDate | Returns the date and time of the TZDate instance as a Date object. |
valueOf | Returns the elapsed time (in milliseconds) from January 1, 1970 UTC to the date and time of the TZDate instance. |
addFullYear | Adds years by a given numeric value. |
addMonth | Adds months by a given numeric value. |
addDate | Adds a number of days to a given numeric value. |
addHours | Adds hours by a given numeric value. |
addMinutes | Adds minutes to a given numeric value. |
addSeconds | Adds seconds to the given numeric value. |
addMilliseconds | Adds milliseconds to a given numeric value. |
getTime | Returns the elapsed time (in milliseconds) from January 1, 1970 UTC to the date and time of the TZDate instance. |
getFullYear | Returns the year of the TZDate instance date and time. |
getMonth | Returns the month of the TZDate instance date and time. Month is a zero-based value. (for example, 2 in case of March) |
getDate | Returns the day of the TZDate instance date and time. |
getDay | Returns a numeric value corresponding to the day of the week of the TZDate instance date and time. 0 represents Sunday. |
getHours | Returns the hours of the TZDate instance date and time. |
getMinutes | Returns the minutes of the TZDate instanc date and timee. |
getSeconds | Returns the seconds of the TZDate instanc date and timee. |
getMilliseconds | Returns the milliseconds of the TZDate instanc date and timee. |
getTimezoneOffset | Returns the timezone offset of the TZDate instance in minutes. |
setWithRaw | Sets the day and time of the TZDate instance with individual date and time components. |
setTime | Sets the TZDate instance date and time in milliseconds since January 1, 1970 UTC. |
setFullYear | Sets the year and the date of the TZDate instance as a given numeric value. |
setMonth | Sets the month of the TZDate instance date and time as a given numeric value. Month is a zero-based value. (for example, 2 in case of March) |
setDate | Sets the date of the TZDate instance date and time as a given numeric value. |
setHours | Sets the hours of the TZDate instance date and time as a given numeric value. |
setMinutes | Sets the minutes of the TZDate instance date and time as a given numeric value. |
setSeconds | Sets the seconds of the TZDate instance date and time as a given numeric value. |
setMilliseconds | Sets the milliseconds of the TZDate instance as a given numeric value. |
tz | Returns a new TZDate instance following the given timezone. |
local | Returns a new TZDate instance following the system timezone. |
- Type:
toString(): string
- Returns:
string
- a string representing the date and time of the TZDate instance
Returns the TZDate instance date and time as a string. It has the same format as the toString()
function of the Date object.
- Type:
toDate(): Date
- Returns:
Date
- a Date object representing the date and time of the TZDate instance
Returns the date and time of the TZDate instance as a native Date object.
- Type:
valueOf(): number
- Returns the elapsed time (in milliseconds) from January 1, 1970 UTC to the date and time of the TZDate instance.
Returns the elapsed time (in milliseconds) from January 1, 1970 UTC to the date and time of the TZDate instance.
- Type:
addFullYear(y: number): TZDate
- Parameters
y
- the number of years to add
- Returns:
TZDate
- changed TZDate
Adds years by a given numeric value. Changes an existing TZDate instance and returns it.
- Type:
addFullYear(y: number): TZDate
- Parameters
y
- the number of years to add
- Returns:
TZDate
- changed TZDate
Adds months by a given numeric value. Changes an existing TZDate instance and returns it.
- Type:
addDate(d: number): TZDate
- Parameters
d
- the number of days to append
- Returns:
TZDate
- changed TZDate
Adds a number of days to a given numeric value. Changes an existing TZDate instance and returns it.
- Type:
addHours(h: number): TZDate
- Parameters
h
- the number of times to append
- Returns:
TZDate
- changed TZDate
Adds hours by a given numeric value. Changes an existing TZDate instance and returns it.
- Type:
addMinutes(M: number): TZDate
- Parameters
M
- the number of minutes to add
- Returns:
TZDate
- changed TZDate
Adds minutes to a given numeric value. Changes an existing TZDate instance and returns it.
- Type:
addSeconds(s: number): TZDate
- Parameters
M
- the number of seconds to add
- Returns:
TZDate
- changed TZDate
Adds seconds to the given numeric value. Changes an existing TZDate instance and returns it.
- Type:
addMilliseconds(ms: number): TZDate
- Parameters
ms
- the number of milliseconds to add
- Returns:
TZDate
- changed TZDate
Adds milliseconds to a given numeric value. Changes an existing TZDate instance and returns it.
- Type:
getTime(): number
- Returns the elapsed time (in milliseconds) from January 1, 1970 UTC to the date and time of the TZDate instance.
Returns the elapsed time (in milliseconds) from January 1, 1970 UTC to the date and time of the TZDate instance.
- Type:
getFullYear(): number
- Returns:
number
- the year of the date and time of the TZDate instance
Returns the year of the TZDate instance date and time.
- Type:
getMonth(): number
- Returns:
number
- the month of the date and time of the TZDate instance
Returns the month of the TZDate instance date and time. Month is a zero-based value. (ex. 2
in case of March)
- Type:
getDate(): number
- Returns:
number
- the day of the TZDate instance date and time
Returns the day of the TZDate instance.
- Type:
getDay(): number
- Returns:
number
- a numeric value corresponding to the day of the week for the date and time of the TZDate instance
Returns a numeric value corresponding to the day of the week of the TZDate instance date and time. 0 represents Sunday.
- Type:
getHours(): number
- Returns:
number
- the hours of the TZDate instance date and time
Returns the hours of the TZDate instance date and time.
- Type:
getMinutes(): number
- Returns:
number
- the minutes of the TZDate instance date and time
Returns the minutes of the TZDate instance date and time.
- Type:
getSeconds(): number
- Returns:
number
- the seconds of the date and time of the TZDate instance
Returns the seconds of the TZDate instance date and time.
- Type:
getMilliseconds(): number
- Returns:
number
- the milliseconds of the date and time of the TZDate instance
Returns the milliseconds of the TZDate instance date and time.
- Type:
getTimezoneOffset(): number
- Returns:
number
- the timezone offset of the TZDate instance in minutes
Returns the timezone offset of the TZDate instance in minutes.
- Type:
setWithRaw(y: number, m: number, d: number, h: number, M: number, s: number, ms: number): TZDate
- Parameters
y
: a year to specifym
: a month to specifyd
: a day to specifyh
: hours to specifyM
: minutes to specifys
: seconds to specifyms
: milliseconds to specify
- Returns:
TZDate
- changed TZDate
Specifies the date and time of the TZDate instance with individual date and time components. Changes an existing TZDate instance and returns it.
- Type:
setTime(t: number): number
- Parameters
t
: the number of milliseconds since January 1, 1970 UTC to specify
- Returns:
number
- the elapsed time (in milliseconds) from January 1, 1970 UTC to the date and time of the changed TZDate instance.
Set the TZDate instance date and time with the elapsed time(in milliseconds) since January 1, 1970 UTC. Changes an existing TZDate instance.
- Type:
setFullYear(y: number, m?: number, d?: number): number
- Parameters
y
: a year to specifym
: The month to specify. If not specified, the month of the existing TZDate instance date and time is maintained.d
: The day to specify. If not specified, the day of the existing TZDate instance is maintained.
- Returns:
number
- the elapsed time (in milliseconds) from January 1, 1970 UTC to the date and time of the changed TZDate instance.
Specifies the year of the date and time of the TZDate instance as a given numeric value. You can additionally specify the month and date. Change an existing TZDate instance.
- Type:
setMonth(m: number, d?: number): number
- Parameters
m
: a month to specifyd
: The day to specify. If not specified, the day of the existing TZDate instance is maintained.
- Returns:
number
- the elapsed time (in milliseconds) from January 1, 1970 UTC to the date and time of the changed TZDate instance.
Specifies the month of the date and time of the TZDate instance as a given numeric value. Month is a zero-based value. (for example, 2
in case of March) The day can also be additionally specified. Changes an existing TZDate instance.
- Type:
addDate(d: number): TZDate
- Parameters
d
: a day to specify
- Returns:
number
- the elapsed time (in milliseconds) from January 1, 1970 UTC to the date and time of the changed TZDate instance.
Specifies the day of the TZDate instance as a given numeric value. Changes an existing TZDate instance.
- Type:
setHours(h: number, M?: number, s?: number, ms?: number): number
- Parameters
h
: hours to specifyM
: minutes to specify. If not specified, the minutes of the existing TZDate instance date and time are maintained.s
: seconds to specify. If not specified, the seconds of the existing TZDate instance date and time are maintained.ms
: milliseconds to specify. If not specified, the milliseconds of the old TZDate instance date and time are maintained.
- Returns:
number
- the elapsed time (in milliseconds) from January 1, 1970 UTC to the date and time of the changed TZDate instance.
Specifies the hour of the TZDate instance date and time as a given numeric value. You can additionally specify minutes, seconds, and milliseconds. Changes an existing TZDate instance.TZDate
- Type:
setMinutes(M: number, s?: number, ms?: number): number
- Parameters
M
: minutes to specifys
: seconds to specify. If not specified, the seconds of the existing TZDate instance date and time are maintained.ms
: milliseconds to specify. If not specified, the milliseconds of the old TZDate instance date and time are maintained.
- Returns:
number
- the elapsed time (in milliseconds) from January 1, 1970 UTC to the date and time of the changed TZDate instance.
Specifies the minute of the TZDate instance date and time as a given numeric value. Seconds and milliseconds can be additionally specified. Changes an existing TZDate instance.
- Type:
setSeconds(s: number, ms?: number): number
- Parameters
s
: seconds to specifyms
: milliseconds to specify. If not specified, the milliseconds of the old TZDate instance date and time are maintained.
- Returns:
number
- the elapsed time (in milliseconds) from January 1, 1970 UTC to the date and time of the changed TZDate instance.
Specifies the second of the TZDate instance date and time as a given numeric value. You can also specify additional milliseconds. Changes an existing TZDate instance.
- Type:
setMilliseconds(ms: number): number
- Parameters
ms
: milliseconds to specify
- Returns:
number
- the elapsed time (in milliseconds) from January 1, 1970 UTC to the date and time of the changed TZDate instance.
Specifies the number of milliseconds of the date and time of the TZDate instance as a given numeric value. Changes an existing TZDate instance.
- Type:
tz(tzValue: string | 'Local' | number): TZDate
- Parameters
tzValue
: timezone to specify
- Returns:
TZDate
- a new TZDate instance following the given timezone.
Returns a new TZDate instance following the given timezone. tzValue
can be specified as the timezone name of the IANA time zone database, the timezone offset numeric value, and 'Local'
. If 'Local'
is specified, the system timezone is followed. It does not change the existing TZDate instance, but returns a new TZDate instance.
- Type:
local(tzValue?: string | number): TZDate
- Parameters
tzValue
: The timezone the TZDate instance follows. If not specified, it is calculated based on the time zone of the TZDate instance.
- Returns:
TZDate
- a new TZDate instance following the system timezone
Returns a new TZDate instance conforming to the system timezone. tzValue
can be used when the TZDate instance follows a timezone other than the one assigned to it. If there is no tzValue
, it is calculated based on the time zone of the TZDate instance. It does not change the existing TZDate instance, but returns a new TZDate instance.