toDate
function toDate(value): Date;Defined in: datetime-utils.ts:86
Convert a variety of date/time-like values into a JS Date.
Parsing strategy (in order):
Date→ clonedDateTemporal.*instances → converted via UTC epoch millisecondsnumber→new Date(number)(epoch milliseconds)string→ tryTemporal.ZonedDateTime,Temporal.Instant,Temporal.PlainDateTime,Temporal.PlainDate(all interpreted as UTC where needed), then fall back tonew Date(string)
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
DateLike |
Returns
Section titled “Returns”Date
Throws
Section titled “Throws”If the value is invalid or out of JS Date range.
Example
Section titled “Example”toDate(new Date());toDate(Temporal.Instant.from("2025-01-01T00:00:00Z"));toDate(Temporal.ZonedDateTime.from("2025-01-01T00:00[UTC]"));toDate(1735689600000); // epoch mstoDate("2025-01-01T00:00:00Z");toDate("2025-01-01"); // interpreted as 00:00:00Z