Temporal#
@formatjs/temporal provides Temporal's eight value types, Now, and 16
calendars in JavaScript.
Installation#
npm install @formatjs/temporal
Import the namespace without changing globals:
import {Temporal} from '@formatjs/temporal'
const meeting = Temporal.ZonedDateTime.from(
'2020-03-07T12:00-05:00[America/New_York]'
)
meeting.add({days: 1}).toString()
// '2020-03-08T12:00:00-04:00[America/New_York]'
meeting.add({hours: 24}).toString()
// '2020-03-08T13:00:00-04:00[America/New_York]'
A calendar day can differ from 24 hours when the offset changes.
Choose an entry point#
| Entry | Use it for |
|---|---|
@formatjs/temporal | Isolated namespace using installed Intl data |
@formatjs/temporal/polyfill.js | Global installation when the host Temporal API is missing or incomplete |
@formatjs/temporal/polyfill-force.js | Unconditional global installation |
@formatjs/temporal/standalone.js | Isolated namespace with bundled calendar and time-zone data |
The installation entries also provide Date.prototype.toTemporalInstant.
Calendars and time-zone data#
Load any Intl polyfills and their data before importing Temporal. The default entry captures installed DateTimeFormat for named time zones and Umm al-Qura data. UTC and numeric offsets work without Intl.
Native Intl supplies offsets, so the default entry samples them to find transitions. Closely spaced changes can escape detection if the offsets at both ends of a sample interval match. Use standalone for bundled IANA history and recurring rules beyond 2100. Update the package when those rules change.
Chinese and Dangi use compact ICU4X data for 1900–2102 and an arithmetic approximation outside that range. The default entry uses host Umm al-Qura data for AH 1300–1600, with civil arithmetic outside that range.
Temporal.Now uses the system time zone. Without DateTimeFormat it uses
the current offset from Date. A failed lookup or unusable identifier falls
back to UTC. If a configured clock throws, Now uses the runtime wall clock.
Explicit invalid zone arguments still throw.
Calendar-unit Duration totals validate both interpolation endpoints. Near date
limits, an exact result or a zero zoned total can still throw RangeError.
Locale formatting#
import '@formatjs/temporal/polyfill.js'
Temporal.PlainDate.from('2026-11-17').toLocaleString('en', {
dateStyle: 'long',
})
// 'November 17, 2026'
Date and time values use DateTimeFormat.
Duration uses DurationFormat. If the
formatter is unavailable, toLocaleString() returns an ISO representation.
Create formatters after global Temporal installation. To use an isolated
namespace with FormatJS formatters, register it with
DateTimeFormat.__addTemporalNamespace(Temporal) or
DurationFormat.__addTemporalNamespace(Temporal) on the FormatJS class in use.
Hermes and Rust#
Use TypeScript on Hermes or rebuild your app with the native Hermes SDK for Rust-backed Temporal. For native Rust applications, see Temporal for Rust.
Conformance and verification#
Test262 covers JavaScript behavior on Node.js and Hermes. Independent ICU fixtures cover calendar arithmetic, offsets, transitions, rounding, and formatting. Calendar fixtures verify specific authority ranges. The implementation guide links to test profiles, documented data-version exclusions, and provider limits.