JavaScript Format Temporal Dates
Convert Dates to Strings
Temporal values can be converted to strings in different ways.
Temporal values can be formatted as:
- ISO strings (toString)
- Local strings (toLocaleString)
- Fully customized strings (Intl.DateTimeFormat)
ISO 8601 Strings
An ISO 8601 string represents dates and times in a structured and sortable format.
It uses a 4-digit year, 2-digit month, 2-digit day and a 'T' separator for time, often in UTC (ending with 'Z' for Zulu):
| Format | Format | Example |
|---|---|---|
| Date & Time UTC | YYYY-MM-DDTHH:mm:ssZ | 2026-05-17T14:30:00Z |
| Date & Time Offset | YYYY-MM-DDTHH:mm:ss±hh:mm | 2026-05-17T14:30:00+01:00 |
| Date only | YYYY-MM-DD | 2026-05-17 |
| Duration | PnYnMnDTnHnMnS | P3Y6M4DT12H30M5S |
Note
Using ISO 8601 avoids confusion between regional formats like MM/DD/YYYY (US) and DD/MM/YYYY (Europe).
The RFC 9557 Format
RFC 9557 is the primary string format used by JavaScript Temporal date objects to represent zoned date-times and plain dates.
It was created because ISO 8601 and RFC 3339 timestamps only provide UTC offsets (like -05:00), which does not contain enough information to determine the actual geographical time zone or handle future DST (Daylight Saving Time) changes.
RFC 9557 is not strictly a part of the ISO 8601 standard. Instead, it is an extension to RFC 3339, which itself is a simplified "profile" of ISO 8601 designed for internet use.
While these standards are closely related, here is how the relationship works:
- ISO 8601:
The basic international standard for date and time representation. - RFC 3339:
A subset (profile) of ISO 8601 specifically for the internet. - RFC 9557:
An extension to RFC 3339 with new features like time zone names ([Europe/Oslo]) and calendar names ([u-ca=hebrew]).
| Feature | ISO 8601 | RFC 3339 | RFC 9557 |
|---|---|---|---|
| Format | YYYY-MM-DDTHH:MM:SSZ | Same | Same |
| UTC Offset | Yes | Yes | Yes |
| IANA Zone | No | No | [America/New_York] |
| Calendar | ISO only | ISO only | [u-ca=hebrew] |
| Compabile | The Standard | Subset of ISO 8601 | Extends 3339 |
Format with toString()
The toString() method returns a standard ISO string.
Example
const date = Temporal.PlainDate.from("2026-02-17");
let text = date.toString();
Result:
2026-02-17
Format PlainTime
A PlainTime value is formatted as a time string.
Example
const time = Temporal.PlainTime.from("14:30:15");
let text = time.toString();
Result:
14:30:15
Format PlainDateTime
A PlainDateTime value includes both date and time.
Example
const dateTime = Temporal.PlainDateTime.from("2026-02-17T14:30:15");
let text = dateTime.toString();
Result:
2026-02-17T14:30:15
Format ZonedDateTime
A ZonedDateTime string includes the offset and time zone.
Example
const zoned = Temporal.ZonedDateTime.from(
"2026-02-17T14:30:15+01:00[Europe/Oslo]");
let text = zoned.toString();
Result:
2026-02-17T14:30:15+01:00[Europe/Oslo]
Remove Smaller Time Units
You can control how much detail to include.
For example, you can hide seconds or milliseconds.
Example
const time = Temporal.PlainTime.from("14:30:15.123");
let text = time.toString({ smallestUnit: "minute" });
Result:
14:30
Control Fractional Digits
You can choose how many decimal digits to include.
Example
const time = Temporal.PlainTime.from("14:30:15.123456789");
let text = time.toString({ fractionalSecondDigits: 3 });
Result:
14:30:15.123
Format with toLocaleString()
Use toLocaleString() to format a value using the user's locale.
Example
const date = Temporal.PlainDate.from("2026-02-17");
console.log(date.toLocaleString("en-US"));
console.log(date.toLocaleString("de-DE"));
The output depends on the chosen locale.
Format with Intl.DateTimeFormat
Use Intl.DateTimeFormat when you need more control over the output.
Example
const date = Temporal.PlainDate.from("2026-02-17");
const formatter = new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "long",
day: "numeric"
});
let text = formatter.format(date);
Result:
February 17, 2026
Format Date and Time Together
You can format a PlainDateTime with both date and time options.
Example
const dateTime = Temporal.PlainDateTime.from("2026-02-17T14:30:15");
const formatter = new Intl.DateTimeFormat("en-GB", {
year: "numeric",
month: "short",
day: "numeric",
hour: "2-digit",
minute: "2-digit"
});
let text = formatter.format(dateTime);
Format ZonedDateTime in a Locale
When formatting a ZonedDateTime, the time zone is included in the calculation.
Example
const zoned = Temporal.ZonedDateTime.from(
"2026-02-17T14:30:15+01:00[Europe/Oslo]");
const formatter = new Intl.DateTimeFormat("en-US", {
dateStyle: "full",
timeStyle: "short"
});
let text = formatter.format(zoned);
When to Use Each Method
Use
toString()for standard ISO output.Use
toLocaleString()for simple local formatting.Use
Intl.DateTimeFormatfor custom formatting.