The DayPilot.Date constructor creates a new immutable DayPilot date/time value from the current time, an ISO 8601 string, or a JavaScript Date object.
Declaration
new DayPilot.Date(value, isLocal)new DayPilot.Date()new DayPilot.Date(value)new DayPilot.Date(date, isLocal)Parameters
value(string) - date/time value in ISO 8601 format.date (Date)- JavaScript object used to set the initial value. If it isnull, the current local date and time are used.isLocal(boolean) - for a JavaScriptDate, selects local date/time fields when true or the GMT base when false. For an ISO string with a timezone suffix, selects the written fields when true or applies the suffix when false. The default is false.
Possible Values
"2035-01-01"- ISO 8601 date without time."2035-01-01T00:00:00"- ISO 8601 date/time without milliseconds."2035-01-01T00:00:00.000"- ISO 8601 date/time with milliseconds."2035-01-01T00:00:00Z"- ISO 8601 date/time with a UTC suffix."2035-01-01T00:00:00.000Z"- ISO 8601 date/time with milliseconds and a UTC suffix."2035-01-01T00:00:00+01:00"- ISO 8601 date/time with an offset suffix."2035-01-01T00:00:00.000+01:00"- ISO 8601 date/time with milliseconds and an offset suffix.date (Date)- JavaScript Date object accepted by the overloaded constructor.
Notes
DayPilot.Date() creates a new instance using the current local date and time.
DayPilot.Date(value) creates a new instance using a date specified in ISO 8601 format such as "2035-01-01T00:00:00".
DayPilot works with a single idealized timezone, so it is recommended to use date/time formats without explicit time zone information. See also Time Zones [doc.daypilot.org].
DayPilot.Date(date, isLocal) creates a new instance from a JavaScript Date object.
Timezone-Bearing Strings
For an ISO string with Z or an offset such as +02:00, the second argument also controls interpretation. With isLocal set to false (the default), the offset is applied to obtain the UTC value. With isLocal set to true, the written date/time fields are retained and the suffix is ignored. This does not convert the value to the browser’s timezone.
const value = "2027-10-03T10:00:00+02:00";
const utc = new DayPilot.Date(value, false);
const local = new DayPilot.Date(value, true);
console.log(utc.toString()); // "2027-10-03T08:00:00"
console.log(local.toString()); // "2027-10-03T10:00:00"Strings without a timezone suffix represent the written date/time in either mode. The resulting DayPilot.Date does not retain a timezone identifier. Prefer suffix-free values for a schedule expressed in one local business timezone.
Parsing Errors
An unparseable string raises a DayPilot.Exception. When reading user-entered dates in a custom format, use DayPilot.Date.parse() with the expected pattern instead of passing the formatted text to this constructor.
Example
const now = new DayPilot.Date();
const fromString = new DayPilot.Date("2035-01-01T00:00:00");
const fromDate = new DayPilot.Date(new Date(), true);See Also
Time Zones [doc.daypilot.org]
Client-Side Event API [doc.daypilot.org]
Availability
Availability of this API item in DayPilot editions:
| Product | Lite | Pro |
|---|---|---|
| DayPilot for JavaScript |
DayPilot