JavaScript Temporal: Choose the Correct Time Type
Quick answer
Temporal introduces distinct immutable types for instants, calendar dates, wall-clock times, durations and zoned date-times. The TC39 proposal is Stage 4 as of the official July 27, 2026 draft; runtime availability must still be checked.
How it works
Choose Temporal.Instant for an exact time point, Temporal.PlainDate for a date without clock or zone, Temporal.PlainTime for a clock time, Temporal.PlainDateTime for local calendar/clock fields, Temporal.ZonedDateTime for an instant with zone and calendar, and Temporal.Duration for amounts of time. PlainYearMonth and PlainMonthDay model partial calendar dates. Calendar addition and elapsed duration are different operations. Use feature detection rather than assuming a global Temporal; the installed Node runtime lacks it. These examples test type selection and feature-detection logic, not actual Temporal arithmetic.
function supported(api){return typeof api?.PlainDate?.from === "function";} console.log(supported(undefined),supported({}));Expected output in Node.js:
false falseA missing namespace or method fails the capability check; this is a simulated probe.
const models={birthday:"PlainDate",meeting:"ZonedDateTime",audit:"Instant"}; console.log(models.birthday,models.audit);Expected output in Node.js:
PlainDate InstantThese strings represent different domain concepts, not Temporal instances.
Common mistakes
Stage 4 is a standardization milestone, not proof of support in every engine. Do not run Temporal-dependent assessments in an unsupported sandbox.
Practice
Model a birthday with PlainDate, a meeting with ZonedDateTime and an audit timestamp with Instant. In a verified Temporal-enabled runtime, try Temporal.PlainDate.from("2024-02-28").add({days: 2}).toString() and expect 2024-03-01. This optional Temporal snippet is not executed locally.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
JavaScript Temporal: Choose the Correct Time Type — Knowledge Check
Apply the taught concept and predict the output.
Which Temporal type represents a date without time or time zone?
Which type combines an exact instant with time zone information?
What does a Stage 4 TC39 feature status establish about a particular runtime?
What is the exact console output in JavaScript Temporal: Choose the Correct Time Type example 1?
function supported(api){return typeof api?.PlainDate?.from === "function";} console.log(supported(undefined),supported({}));What is the exact console output in JavaScript Temporal: Choose the Correct Time Type example 2?
const models={birthday:"PlainDate",meeting:"ZonedDateTime",audit:"Instant"}; console.log(models.birthday,models.audit);