The DayPilot.Date class represents an immutable date/time value used by DayPilot client-side APIs.
DayPilot uses a special class for representing a DateTime value on the client side.
Shared Instances
The DayPilot.Date class reuses instances for the same points in time.
Same strings
> new DayPilot.Date("2023-01-01T00:00:00") === new DayPilot.Date("2023-01-01T00:00:00");
trueDifferent strings representing the same date/time
> new DayPilot.Date("2023-01-01T00:00:00") === new DayPilot.Date("2023-01-01");
trueDirect Comparison
DayPilot.Date allows direct comparison using >, <, ==, === operators:
> new DayPilot.Date("2023-02-01") > new DayPilot.Date("2023-01-01");
trueThe values are normalized:
> new DayPilot.Date("2023-01-01") === new DayPilot.Date("2023-01-01T00:00:00");
trueImmutability
The DayPilot.Date instances are immutable. The internal .ticks and .value properties are read-only.
.value is implemented as a read-only property so you can inspect its value in the Chrome console.
.ticks remains internal, implemented using a getter.
Converting to a Date Object
Use toDate() to get a Date object that stores the DayPilot.Date value as the GMT base.
Use toDateLocal() to get a Date object that stores the DayPilot.Date value as the local part.
DayPilot.Date has the same methods as Date. You can use them to read component values such as getYear() and getMonth().
Converting from a Date Object
Use new DayPilot.Date(date) to create a DayPilot.Date object from the GMT base of the supplied Date object.
Use new DayPilot.Date(date, true) to create a DayPilot.Date object from the local representation of the supplied Date object.
ISO 8601
Calling toString() without parameters returns the ISO 8601 representation of the input value, for example "2023-05-27T13:15:00".
If the date doesn't have milliseconds set it is normalized as "yyyy-MM-ddTHH:mm:ss".
If the date has milliseconds set it is normalized as "yyyy-MM-ddTHH:mm:ss.fff".
No time zone identifier is used. See also the Time Zones article.
Formatting
You can use toString(format) to get a locally formatted string.
See toString(format) for the list of supported format strings.
Example - sending the value to the server
> const date = new DayPilot.Date("2023-05-27T13:15:00");
> date.toString()
"2015-05-27T13:15:00"
Example - presenting the value to the user
> const date = new DayPilot.Date("2023-05-27T13:15:00");
> date.toString("M/d/yyyy HH:mm")
"5/27/2023 13:15"
Example - get a Date object that returns a correct string using .toString()
> const date = new DayPilot.Date("2023-05-27T13:15:00");
> date.toDateLocal().toString();
'Sat May 27 2023 13:15:00 GMT+0200 (Central European Summer Time)'Time Zones
The controls work with an idealized continuous timezone in order to perform date/time calculations consistently.
Continuous = Unlike most local timezones it doesn't have daylight saving time, so there are no unexpected breaks.
Idealized = This timezone behaves like GMT and it uses GMT internally, but in a typical setup you will pretend that this is your local timezone and ignore the fact that it is incorrect for events that span over the DST change date.
By calling toDateLocal() you say: I pretend the idealized timezone is my local timezone.
String Parsing
Use DayPilot.Date.parse(string, pattern, locale) to read the value from a custom-formatted string.
Date/Time Calculations
The following methods are available:
addMilliseconds()
addSeconds()
addMinutes()
addHours()
addDays()
addMonths()
addYears()
firstDayOfMonth()
lastDayOfMonth()
firstDayOfWeek()
firstDayOfYear()
getDatePart()
getTimePart()
daysInMonth()
daysInYear()
dayOfWeek()
dayOfYear()
The original DayPilot.Date object is not modified.
Creating DayPilot.Date Objects
DayPilot.Date.now() - current date/time from the local date representation
DayPilot.Date.today() - today from the local date representation
new DayPilot.Date(isoString) - from an ISO 8601 string
DayPilot.Date.fromYearMonthDay(year[, month, [day]]) - from the specified year/month/day (missing month = 1, missing day = 1)
DayPilot.Date.parse(string, pattern[, locale]) - from a string in the specified format
Time Zones [doc.daypilot.org]