· By John Kavanagh

A Brief Look at JavaScript's Temporal Dates and Times API

A photograph of a wooden boardwalk following a rocky shoreline beside the sea.
Image by Borja Verbena, licensed from Unsplash.

In Brief

Temporal separates calendar dates, local times, instants, and zoned date‑times into immutable types. Use Instant.fromEpochMilliseconds() for millisecond timestamps, and convert documented Unix seconds explicitly. Calendar days can differ from 24 elapsed hours across clock changes. Temporal reached Stage 4 in March 2026, but isn't in the published ECMAScript 2026 edition; check runtime support and use a tested polyfill where needed.

The JavaScript Date object has been with us since the language's early days in 1995. Its API was modelled on Java's java.util.Date, which helps explain some of its more peculiar decisions. More than thirty years later, we're still explaining why November is month 10 in one constructor, but 11 in a date string.

I've written before about checking whether today falls between two dates and finding the weekday for a date. Neither sounds particularly difficult. Both become more interesting once time zones get involved.

Temporal gives us a better starting point: separate types for the different things we mean by a date or time. That distinction is more useful than it might initially sound. A birthday isn't an instant, and "tomorrow at noon" isn't always 24 hours away.


Why Date Can Be Awkward

Date became part of the first ECMAScript specification in 1997. ES5 later standardised its date‑time string format and added toISOString(). We haven't been completely abandoned, then, but the underlying model has stayed much the same.

A valid Date stores a number of milliseconds since the Unix epoch. It doesn't store the time zone from the string used to create it. Its ordinary getters interpret that instant in the host's local time zone, whilst the UTC getters use UTC.

Time Zones and Parsing

An ISO date‑only string, such as 2024-11-01, is interpreted as midnight UTC. An ISO date‑time string without an offset, such as 2024-11-01T12:00:00, uses the host's local time. Adding Z makes that second string UTC instead. These are specified behaviours, but they're easy to mix up.

Non‑standard strings are another matter. 11/01/2024 is not a portable way to ask JavaScript for a particular date. As a Brit, I obviously have an opinion about which way round it *ought* to be read. The parser isn't obliged to share it. Its behaviour is implementation‑dependent, rather than a reliable reflection of the user's regional preferences.

To be fair to Date, formatting an instant in a named time zone is already possible through Intl.DateTimeFormat. The awkward part is that Date itself doesn't retain that zone or provide calendar arithmetic in an arbitrary named zone. Formatting a London appointment and moving it to the following day are different jobs.

Mutation and Precision

The setters on Date modify the original object. If two parts of an application hold the same instance, a call to setDate() in one can quietly change what the other sees. Copying the value first works, but it's another thing to remember.

Date also represents time only to the millisecond. That's perfectly adequate for plenty of applications. It becomes a limitation when a database or API supplies a timestamp with more fractional digits and we'd like to preserve them. More on that shortly.


Introducing Temporal

When I first published this article in February 2025, Temporal was at Stage 3. It reached Stage 4 on 11 March 2026.

In TC39's process, Stage 4 means the feature is complete and ready for inclusion in the standard, with compatible implementations and acceptance tests behind it. It doesn't mean every runtime has shipped it, and it isn't the same thing as publication in a particular annual edition.

That last distinction matters here. As checked in November 2026, the published ECMAScript 2026 specification does not include the Temporal API. TC39's finished‑proposals list gives 2027 as its expected publication year. The Temporal specification remains the detailed reference for the API.

The useful change for us is its design. Temporal values are immutable, so operations return new values. We also choose a type that describes what we're actually working with, rather than squeezing everything into Date and hoping the next developer remembers our assumptions.


Choosing the Right Temporal Type

These are the types I'd start with:

  • Temporal.PlainDate: a calendar date, such as 2024-11-01, without a time or time zone. Useful for a delivery date or date of birth.
  • Temporal.PlainTime: a time of day, such as 15:30, without a date or time zone.
  • Temporal.PlainDateTime: a date and time without a time zone. It describes what a calendar and clock say, but doesn't identify a unique instant.
  • Temporal.Instant: a specific point on the timeline. Useful for an event timestamp returned by an API. It doesn't carry a calendar or time zone.
  • Temporal.ZonedDateTime: an instant together with a time zone and calendar. Useful when an appointment's local date and time matter.
  • Temporal.Duration: an amount of time expressed in units such as months, days, hours, and seconds. Converting between those units can require a starting point.

There are also PlainYearMonth and PlainMonthDay for partial dates, and Temporal.Now for reading the current time. We don't need the entire API to get started.

The examples below use the default ISO calendar. Run each example separately, with native Temporal available or with the polyfill import shown in the support section. The weekday function is TypeScript; the other examples are ordinary JavaScript.


Parsing Dates Without Guesswork

Creating a calendar date is straightforward:

const date = Temporal.PlainDate.from('2024-11-01');
console.log(date.toString());  //=> "2024-11-01"

Temporal.PlainDate.from('11/01/2024') throws a RangeError, as does the impossible date string 2024-02-30. We get a failure to handle instead of an invalid object or a surprising interpretation.

"Temporal only accepts ISO 8601" is still too broad an explanation. The supported string forms depend on the type, including extensions for time zones and calendars. Instant.from() needs an offset or Z in a string to identify the instant. ZonedDateTime.from() needs a bracketed time zone identifier. The plain types deliberately have no time zone; some extra information can be ignored when extracting their fields.

For example, PlainDate.from('2024-11-01T12:00:00') extracts the date. That makes it convenient, but it isn't validation that an incoming string contains *only* a date. If your API promises exactly YYYY-MM-DD, check that shape as well.

Object input has another useful distinction. The default overflow behaviour constrains out‑of‑range fields, so PlainDate.from({ year: 2024, month: 2, day: 30 }) produces 29 February. Pass { overflow: 'reject' } as the second argument when you want that input rejected. Invalid date strings are rejected regardless of this option.


Calendar Arithmetic and Durations

Adding a week is pleasantly readable:

const today = Temporal.PlainDate.from('2024-11-01');
const nextWeek = today.add({ days: 7 });
console.log(nextWeek.toString());  //=> "2024-11-08"

The original today value still represents 1 November. That's the immutability doing its job, without us needing to make a defensive copy.

Months need a decision about overflow. What should one month after 31 January mean?

const january = Temporal.PlainDate.from('2025-01-31');
console.log(january.add({ months: 1 }).toString());
// 2025-02-28
console.log(january.toString());
// 2025-01-31

By default, the result is constrained to the last valid day of February. january.add({ months: 1 }, { overflow: 'reject' }) throws instead. Temporal makes that choice explicit; it doesn't decide which behaviour your billing system ought to have. Repeatedly adding a month to the constrained result can also lose the original "last day of the month" intention.

Calculating a difference gives us a Duration:

const start = Temporal.PlainDate.from('2024-11-01');
const end = Temporal.PlainDate.from('2024-12-01');
const duration = start.until(end);
console.log(duration.toString());  //=> "P30D" (30 days)

P30D is the ISO duration notation for 30 days. Asking for start.until(end, { largestUnit: 'months' }) instead gives P1M for these particular dates. Neither result means that every month has 30 days.

Likewise, a calendar day isn't necessarily 24 elapsed hours in a named time zone. A duration containing months or days needs the appropriate calendar and, for zoned calculations, time zone context. There's no universal "milliseconds in a month" conversion waiting to be discovered.


Working with Unix Timestamps

A Unix timestamp measures time from midnight at the start of 1 January 1970 UTC, ignoring leap seconds. APIs and command‑line tools often supply it in seconds, whereas JavaScript's Date.now() and Date#getTime() use milliseconds. A field named timestamp doesn't tell us which convention its author chose.

For epoch milliseconds, use Temporal.Instant.fromEpochMilliseconds():

const timestamp = 1730462400000;
const instant = Temporal.Instant.fromEpochMilliseconds(timestamp);
console.log(instant.toString());
// 2024-11-01T12:00:00Z
console.log(instant.epochMilliseconds);
// 1730462400000

The trailing Z means UTC. It describes how we're displaying the instant, rather than a time zone stored inside it.

For an API documented to return whole Unix seconds, convert the units explicitly:

const timestampInSeconds = 1730462400;
const instant = Temporal.Instant.fromEpochMilliseconds(
  timestampInSeconds * 1000
);
console.log(instant.toString());
// 2024-11-01T12:00:00Z

Temporal doesn't detect the units. Passing that seconds value directly to fromEpochMilliseconds() would produce a perfectly valid instant in January 1970. Counting digits isn't a dependable fix either. Establish the source's documented units and validate the input accordingly.

Nanoseconds and BigInt

For finer‑grained timestamps, there is a separate constructor:

const instant = Temporal.Instant.fromEpochNanoseconds(
  1730462400000000000n
);
console.log(instant.epochNanoseconds);
// 1730462400000000000n

The n creates a BigInt. Epoch nanosecond values around the present day are far beyond Number.MAX_SAFE_INTEGER, so a regular number cannot preserve every integer. Keep a nanosecond value as a BigInt, or receive it as a decimal string and convert that string with BigInt(). Converting an already rounded number afterwards won't recover the missing digits. JSON doesn't serialise BigInt directly, which is another reason to agree a string representation with the API.

Negative epoch values represent instants before 1970. The range is finite: Instant accepts values within 100 million days either side of the epoch, and out‑of‑range values throw. fromEpochMilliseconds() requires an integer number of milliseconds; fromEpochNanoseconds() takes a BigInt. Fractional Unix seconds need an explicit precision and conversion policy rather than an assumption that multiplication will always produce an exact integer.

Older examples may show fromEpochSeconds() or an epochSeconds property. Those were removed during Temporal's development; use the current millisecond or nanosecond APIs instead.

Precision isn't Clock Accuracy

Nanosecond precision describes what the value can represent. Measurement resolution describes the increments supplied by the clock or source. Clock accuracy describes how close that reading is to the actual time.

Keeping nine fractional digits doesn't make a laptop clock nine digits more trustworthy. Temporal.Now.instant() can't promise nanosecond‑accurate measurements, and converting a millisecond timestamp won't invent additional detail. Temporal can preserve a precise timestamp supplied by another system; it doesn't establish how accurately that timestamp was measured. For timing how long some code takes, a monotonic timer such as performance.now() is generally the more appropriate tool.


Moving Between Date and Temporal

Existing libraries will continue to expect Date, so a practical migration needs to work in both directions:

const date = new Date('2024-11-01T12:00:00Z');
const instant = Temporal.Instant.fromEpochMilliseconds(
  date.getTime()
);
const originalDate = new Date(instant.epochMilliseconds);
console.log(instant.toString());
// 2024-11-01T12:00:00Z
console.log(originalDate.toISOString());
// 2024-11-01T12:00:00.000Z
console.log(originalDate.getTime() === date.getTime());
// true

Both values refer to the same instant. There is no local time zone conversion in that round trip. An invalid Date has a NaN timestamp, so validate it before conversion if the input might be invalid.

The native API also provides Date.prototype.toTemporalInstant(). The explicit millisecond route above works with the imported polyfill without modifying Date.prototype.

Going back to Date discards sub‑millisecond precision:

const precise = Temporal.Instant.from('2024-11-01T12:00:00.123456789Z');
console.log(new Date(precise.epochMilliseconds).toISOString());
// 2024-11-01T12:00:00.123Z

epochMilliseconds floors to the millisecond, including for instants before the epoch. Keep the original Instant if those smaller units matter.

A ZonedDateTime can become an Instant through toInstant(). A PlainDateTime cannot identify one until we've chosen a time zone and resolved any ambiguity. Attaching Z to its string would silently assert UTC, which is only correct if UTC was what we meant.


Time Zones and the Missing Hour

An instant from a log can be viewed in different regions without changing when the event happened:

const instant = Temporal.Instant.fromEpochMilliseconds(1730462400000);
console.log(instant.toZonedDateTimeISO('Europe/London').toString());
// 2024-11-01T12:00:00+00:00[Europe/London]
console.log(instant.toZonedDateTimeISO('America/New_York').toString());
// 2024-11-01T08:00:00-04:00[America/New_York]

The IANA identifier, such as Europe/London, carries regional rules that a fixed offset cannot. London isn't always UTC, despite what a November example might suggest.

Consider noon on the day before the UK's spring clock change in 2025:

const start = Temporal.ZonedDateTime.from(
  '2025-03-29T12:00:00+00:00[Europe/London]'
);
const nextDay = start.add({ days: 1 });
const after24Hours = start.add({ hours: 24 });
console.log(nextDay.toString());
// 2025-03-30T12:00:00+01:00[Europe/London]
console.log(after24Hours.toString());
// 2025-03-30T13:00:00+01:00[Europe/London]
console.log(start.until(nextDay, { largestUnit: 'hours' }).hours);
// 23

Adding a calendar day preserves noon in London. Adding 24 hours measures elapsed time and lands at 1pm. The clocks have taken their annual liberty with our expectations.

For a daily appointment, the calendar interpretation may be right. For a timeout, elapsed hours may be right. Plain dates don't have daylight saving transitions, whilst Instant arithmetic uses time units rather than calendar days. Choose the type and units to match the question.

There are still decisions to make when a local time doesn't exist, or occurs twice during the autumn clock change. ZonedDateTime.from() offers a disambiguation option. Its default, compatible, chooses the earlier occurrence when a time repeats and moves forward across a gap. For booking input, I might prefer { disambiguation: 'reject' } so the user can resolve an ambiguous or missing time explicitly.

The regional rules also come from the runtime's time zone data. Governments can change those rules, so future appointments still need a policy about whether their local wall time or absolute instant takes priority. Temporal gives us the information to express that policy; it doesn't remove the policy.

The Temporal date and time regression fixtures let you run these London clock changes with both the polyfill and native Chromium. They also check the autumn overlap and catch a timestamp sent in the wrong unit.


Finding the Day of the Week

Returning to that interview question, a calendar date is exactly what we need:

const getDayOfWeek = (dateString: string): string => {
  if (!/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test(dateString) ||
      dateString.startsWith('0000-')) {
    throw new RangeError('Expected a date from 0001-01-01 to 9999-12-31');
  }
  const date = Temporal.PlainDate.from(dateString);
  return date.toLocaleString('en-GB', { weekday: 'long' });
};
console.log(getDayOfWeek('2024-11-01'));
// Friday
console.log(getDayOfWeek('2022-01-01'));
// Saturday

The shape and year checks preserve the input rules of my earlier article. Temporal then validates the calendar date, so an impossible date throws. We never turn it into midnight in somebody's time zone just to find its weekday.

Date can produce a weekday name too, using toLocaleDateString('en-GB', { weekday: 'long', timeZone: 'UTC' }) after validating a date‑only input. The advantage here is the date‑only model, rather than an ability to print "Friday" that JavaScript somehow lacked before.

For ordering values, use the relevant compare() method. For example, Temporal.PlainDate.compare(first, second) returns -1, 0, or 1. Use equals() for value equality; === compares object identity, and relational operators such as < aren't supported for Temporal values.


Temporal vs. Date

Here's the comparison I'd keep in mind when choosing between them:

ConcernDateTemporal
What it representsAn instant in millisecondsSeparate types for calendar values, instants, zoned values, and durations
ChangesSetters mutate the instanceOperations return new values
Named time zonesFormatting through Intl; local/UTC methods on DateZone‑aware representation and arithmetic with ZonedDateTime
ParsingSpecified date‑time format, plus implementation‑dependent formsType‑specific formats and explicit options; not a general human‑date parser
PrecisionMillisecondsUp to nanoseconds, depending on the type; no promise of clock accuracy
CompatibilityWidely availableCheck the exact runtime and polyfill requirements

A working Date integration doesn't become wrong because Temporal exists. I'd be more inclined to introduce Temporal where calendar dates, named zones, or arithmetic are already making the code awkward, then convert at the edges where another library still expects Date.


Browser Support and Using the Polyfill

As checked on 16 November 2026, native Temporal shipped in Firefox 139 and Chrome 144, with Chromium‑based Edge following that implementation. Node.js 26 enabled it by default. Don't assume an older Node deployment has it simply because a newer browser does.

Safari needs particular care. The current MDN compatibility data lists Safari 27.3, but Apple's 27.3 release notes identify that release as a beta at this check. Technology Preview or beta support isn't stable availability for the people using your site. Older browsers, embedded webviews, and Node 22/24 deployments still need an alternative where Temporal isn't available by default.

Check MDN's compatibility table against the actual browsers and runtimes you support. A feature check such as typeof globalThis.Temporal !== 'undefined' can tell you whether the namespace exists; it doesn't replace testing the operations your application uses.

For an environment without native support, @js-temporal/polyfill provides an explicitly imported implementation:

yarn add @js-temporal/polyfill
import { Temporal } from '@js-temporal/polyfill';

const date = Temporal.PlainDate.from('2024-11-01');
console.log(date.toString());
// 2024-11-01

The package doesn't install a global Temporal automatically. Import it in the modules that need it, or use a carefully tested loading strategy. If it is only needed in part of the application, consider loading that code on demand and check the effect on bundle size.

The examples here were checked with polyfill 0.5.1. Pin and test the version you ship, including your time zone and formatting cases; a polyfill release and the current specification aren't automatically identical. The proposal repository's own demonstration polyfill is explicitly not intended for production use.


Wrapping Up

What appeals to me most about Temporal is being able to say what a value means. A date can remain a date. A timestamp can remain an instant. An appointment can carry the time zone that makes its calendar arithmetic meaningful.

We still need to know whether an API sends seconds or milliseconds, decide what month‑end overflow means, and check the environments we're shipping to. Those questions were always there. Temporal makes them easier to see and gives us better tools for answering them.

For new code with awkward date handling, it's well worth trying. Just don't mistake a finished proposal for a compatibility check. The calendar has enough surprises of its own.

Postscript

November 2026: I first published this article on 18 February 2025, when Temporal was still at Stage 3. It reached Stage 4 in March 2026, and native browser and Node.js support has moved on considerably since then. This deserved a proper revisit rather than another small note at the bottom.

I've expanded the examples to cover Unix timestamps, working alongside Date, and what happens when the clocks change, and tightened up the explanations of parsing, arithmetic, and precision. I've also corrected my June note's expectation about ECMAScript 2026: Temporal isn't in that published edition, and TC39 currently lists it for 2027. Safari's available beta support is another reminder that standards maturity and production compatibility are separate questions. Apparently even an article about time needs a little help keeping up with it.

Downloadable Resource

  • Temporal Date and Time Regression Fixtures

    Check timestamp units, month overflow, Date conversions and London clock changes with the imported Temporal polyfill and native Chromium.

    First added

    Download ZIP

Have a complex web platform issue?

Tell me what is blocked, what has changed, and what needs to be true after the fix. I'll come back with a practical next step.