🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to JavaScript Notes
Topic #196

Temporal Formats

Temporal dates can be serialized as strings in different ways:

Col 1 Col 2
Method Description
toString() To a date string in the RFC 9557 / ISO 8601 format.
toLocaleString() To language-sensitive string like "en-US".
Intl.DateTimeFormat() When you need more control over the output.

PlainDate toString()

The toString() method returns a standard ISO string.

Example

const date = Temporal.PlainDate.from("2026-05-17");

let text = date.toString();

PlainTime toString()

A PlainTime value is formatted as a time string.

Example

const time = Temporal.PlainTime.from("14:30:15");

let text = time.toString();

PlainDateTime toString()

A PlainDateTime value includes both date and time.

Example

const dateTime = Temporal.PlainDateTime.from("2026-05-17T14:30:15");

let text = dateTime.toString();

ZonedDateTime toString()

A ZonedDateTime string includes the offset and time zone.

Example

const zoned = Temporal.ZonedDateTime.from("2026-05-17T14:30:15[Europe/Oslo]");

let text = zoned.toString();

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" });

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 });

PlainDate toLocaleString()

Use toLocaleString() to format a value using the user's locale.

Example

const date = Temporal.PlainDate.from("2026-05-17");

let text_us = date.toLocaleString("en-US");

let text_de = date.toLocaleString("de-DE");

The output depends on the chosen locale.


ZonedDateTime toLocaleString()

Example

const zoned = Temporal.ZonedDateTime.from("2026-05-17T14:30:15+01:00[Europe/Oslo]");

let text = zoned.toLocaleString("en-US", {

  dateStyle: "full",

  timeStyle: "short"

});

Format with Intl.DateTimeFormat

Use Intl.DateTimeFormat when you need more control over the output.

Example

const date = Temporal.PlainDate.from("2026-05-17");

const formatter = new Intl.DateTimeFormat("en-US", {

  year: "numeric",

  month: "long",

  day: "numeric"

});

let text = formatter.format(date);

Format Date and Time Together

You can format a PlainDateTime with both date and time options.

Example

const dateTime = Temporal.PlainDateTime.from("2026-05-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);

ZonedDateTime toLocaleString()

The Intl.DateTimeFormat() method does not accept a Temporal.ZonedDateTime object as input.

This design choice prevents conflicts between the time zone held by the ZonedDateTime and the time zone defined in the formatter.

The best solution is to use toLocaleString() instead.

Example

const zoned = Temporal.ZonedDateTime.from("2026-05-17T14:30:15+01:00[Europe/Oslo]");

let text = zoned.toLocaleString("en-US", {

  dateStyle: "full",

  timeStyle: "short"

});

When to Use Each Method

  • Use toString() for standard ISO output.
  • Use toLocaleString() for simple local formatting.
  • Use Intl.DateTimeFormat for custom formatting.

Want to go beyond the notes?

Join CodingNow 2.0's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Temporal Formats – FAQs

Quick answers about learning Temporal Formats in JavaScript.

This free note from CodingNow 2.0 explains Temporal Formats in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on CodingNow 2.0, including Temporal Formats, is 100% free with no signup required.
With focused practice, most students grasp Temporal Formats in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now