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-isTemporal.ZonedDateTime→.toInstant()Temporal.PlainDateTime/Temporal.PlainDate→ interpreted as UTCDate→ epoch millisecondsnumber→ epoch millisecondsstring→ try Temporal parsers, thennew Date(string)as a last resort
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
DateLike |
Returns
Section titled “Returns”Instant
Throws
Section titled “Throws”If the value is invalid or can’t be parsed.
Example
Section titled “Example”toInstant(new Date("2025-01-01T00:00:00Z"));toInstant(Temporal.ZonedDateTime.from("2025-01-01T00:00[UTC]"));toInstant(1735689600000); // epoch mstoInstant("2025-01-01T00:00:00Z");