Date
One old mutable object for many date-time tasks.
Date and Temporal solve overlapping problems, but their mental models are very different. Date is old and universal; Temporal is clearer and more precise.
const date = new Date("2026-01-01T09:30:00Z");
if ("Temporal" in globalThis) {
const plain = Temporal.PlainDate.from("2026-01-01");
}
Dates, Time & Intl
Date is available everywhere and still matters. It represents an instant, but it also exposes many local and UTC component methods on one mutable object.
Temporal separates concepts into types. A plain calendar date is not the same thing as an exact instant. A wall-clock time is not the same thing as a zoned date-time.
The practical path is simple: understand Date because production code still uses it, and learn Temporal because it explains date-time modeling much more clearly.
One old mutable object for many date-time tasks.
Modern namespace with specific types for specific concepts.
Date is universal. Temporal needs support checks in current production work.
Temporal teaches clearer thinking about time.
Examples
const needsBroadSupport = true;
if (needsBroadSupport) {
const instant = new Date("2026-01-01T09:30:00Z");
console.log(instant.toISOString());
}
const value = new Date("2026-01-01");
// Is this a calendar date, a UTC instant, or a local display date?
Code patterns
Dates and time zones become much easier when every example names the concept it represents: instant, local display, UTC output, calendar date, formatted text or zoned time.
Use Date when you need broad support without a polyfill.
const now = new Date(); console.log(now.toISOString());
Use PlainDate when the value is only a date.
if ("Temporal" in globalThis) {
const date = Temporal.PlainDate.from("2026-01-01");
console.log(date.toString());
}
Date setters mutate, so copy first.
const original = new Date("2026-01-01T09:30:00Z");
const changed = new Date(original.getTime());
changed.setUTCDate(changed.getUTCDate() + 7);
Temporal methods usually return a new object.
if ("Temporal" in globalThis) {
const original = Temporal.PlainDate.from("2026-01-01");
const changed = original.add({ days: 7 });
console.log(original.toString());
console.log(changed.toString());
}
Rules that matter
Date-time bugs usually start when storage format, calculation logic and user-facing display are treated as the same thing. Keep those responsibilities separate and the code becomes much easier to trust.
Date is still the universal baseline.
It models date-time concepts more clearly.
Instant, calendar date, wall-clock time and zoned time are different.
Copy Date objects before using setters.
Use "Temporal" in globalThis before browser use.
Even with Temporal, formatting for people still belongs in Intl-style display logic.
Production thinking
The biggest improvement is not only syntax. It is thinking clearly about what kind of time value the code is handling.
Clear date-time modeling leads to clearer user-facing labels and less ambiguous scheduling or status text.
Production migration should be deliberate: keep Date where support matters, introduce Temporal with tests and fallback strategy.
Stable date modeling helps prevent wrong published, modified or event dates in visible and structured content.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
Dates are full of traps. Explain the concept first, then run the code and check whether the output matches your mental model.
Senior audit upgrade
Last reviewed: 11 June 2026. Keep Date for broad legacy compatibility. Use Temporal when your supported runtimes and build process allow it.
Use these references when browser support, syntax details or proposal status matters.
Chapter checkpoint
Finish this chapter by turning the lessons into a small practical proof.
Build a small example that combines three lessons from this chapter.
Can you explain the important tradeoff without reading from the page?