Skip to content

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 → cloned Date
  • Temporal.* instances → converted via UTC epoch milliseconds
  • number → new Date(number) (epoch milliseconds)
  • string → try Temporal.ZonedDateTime, Temporal.Instant, Temporal.PlainDateTime, Temporal.PlainDate (all interpreted as UTC where needed), then fall back to new Date(string)
Parameter Type
value DateLike

Date

If the value is invalid or out of JS Date range.

toDate(new Date());
toDate(Temporal.Instant.from("2025-01-01T00:00:00Z"));
toDate(Temporal.ZonedDateTime.from("2025-01-01T00:00[UTC]"));
toDate(1735689600000); // epoch ms
toDate("2025-01-01T00:00:00Z");
toDate("2025-01-01"); // interpreted as 00:00:00Z