SyntaxStudy
Sign Up
JavaScript The Temporal API (Modern Dates)
JavaScript Advanced 6 min read

The Temporal API (Modern Dates)

Temporal API

The TC39 Temporal proposal provides a modern, immutable date/time API that fixes the many quirks of the legacy Date object. Available as a polyfill today.

Example
// Using @js-temporal/polyfill
import { Temporal } from "@js-temporal/polyfill";

const today = Temporal.PlainDate.today();
// { year: 2024, month: 6, day: 15 }

const tomorrow = today.add({ days: 1 });

const inNY = Temporal.Now.zonedDateTimeISO("America/New_York");

// Duration arithmetic
const duration = Temporal.Duration.from({ hours: 5, minutes: 30 });
const later = Temporal.Now.plainTimeISO().add(duration);
Pro Tip

Temporal is stage 3 at TC39 — use the polyfill in production today and migrate when native support lands.