Skip to content

toInstant

function toInstant(value): Instant;

Defined in: datetime-utils.ts:171

Convert a variety of date/time-like values into a Temporal.Instant.

Parsing strategy (in order):

  • Temporal.Instant → returned as-is
  • Temporal.ZonedDateTime → .toInstant()
  • Temporal.PlainDateTime / Temporal.PlainDate → interpreted as UTC
  • Date → epoch milliseconds
  • number → epoch milliseconds
  • string → try Temporal parsers, then new Date(string) as a last resort
Parameter Type
value DateLike

Instant

If the value is invalid or can’t be parsed.

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