Temporal.ZonedDateTime.prototype.toString()

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The toString() method of Temporal.ZonedDateTime instances returns a string representing this date-time in the RFC 9557 format.

Syntax

js
toString()
toString(options)

Parameters

options Optional

An object containing the following property:

calendarName Optional

Whether to show the calendar annotation ([u-ca=calendar_id]) in the return value. Possible values are:

"auto" (default)

Include the calendar annotation if the calendar is not "iso8601".

"always"

Always include the calendar annotation.

"never"

Never include the calendar annotation. This makes the returned string not recoverable to the same Temporal.ZonedDateTime instance, although the date value still remains the same.

"critical"

Always include the calendar annotation, and add a critical flag: [!u-ca=calendar_id]. Useful when sending the string to certain systems, but not useful for Temporal itself.

fractionalSecondDigits Optional

Either an integer from 0 to 9, or the string "auto". The default is "auto". If "auto", then trailing zeros are removed from the fractional seconds. Otherwise, the fractional part of the second component contains this many digits, padded with zeros or rounded as necessary.

roundingMode Optional

A string specifying how to round off fractional second digits beyond fractionalSecondDigits. See Intl.NumberFormat(). Defaults to "trunc".

smallestUnit Optional

A string specifying the smallest unit to include in the output. Possible values are "minute", "second", "millisecond", "microsecond", and "nanosecond", or their plural forms, which (except "minute") are equivalent to fractionalSecondDigits values of 0, 3, 6, 9, respectively. If specified, then fractionalSecondDigits is ignored.

timeZoneName Optional

Whether to show the time zone name ([time_zone_id]) in the return value. Possible values are:

"auto" (default)

Always include the time zone name.

"never"

Never include the time zone name. This makes the returned string not recoverable to the same Temporal.ZonedDateTime instance.

"critical"

Always include the time zone name, and add a critical flag: [!time)zone_id]. Useful when sending the string to certain systems, but not useful for Temporal itself.

offset Optional

Whether to show the offset (±HH:mm) in the return value. Possible values are:

"auto" (default)

Always include the offset.

"never"

Never include the offset. This makes the returned string not recoverable to the same Temporal.ZonedDateTime instance, if the time zone is included but the time is ambiguous, or if the time zone is also not included.

Return value

A string in the RFC 9557 format representing this date-time. The offset and calendar/time zone annotations are included as specified.

Exceptions

RangeError

Thrown if any of the options is invalid.

TypeError

Thrown if options is not an object or undefined.

Examples

Using toString()

js
const zdt = Temporal.ZonedDateTime.from(
  "2021-08-01T12:34:56[America/New_York]",
);
console.log(zdt.toString()); // '2021-08-01T12:34:56-04:00[America/New_York]'

Even for the UTC time zone, the offset is +00:00, not Z:

js
const zdt = Temporal.ZonedDateTime.from("2021-08-01T12:34:56[UTC]");
console.log(zdt.toString()); // '2021-08-01T12:34:56+00:00[UTC]'

Using options

For examples with rounding times, see Temporal.PlainTime.prototype.toString(). For examples with displaying calendars, see Temporal.PlainDate.prototype.toString(). Here we show controlling the display of time zone and offset:

js
const zdt = Temporal.ZonedDateTime.from(
  "2021-08-01T12:34:56[America/New_York]",
);
console.log(zdt.toString({ timeZoneName: "auto", offset: "never" })); // '2021-08-01T12:34:56[America/New_York]'
console.log(zdt.toString({ timeZoneName: "never", offset: "auto" })); // '2021-08-01T12:34:56-04:00'
console.log(zdt.toString({ timeZoneName: "never", offset: "never" })); // '2021-08-01T12:34:56'
console.log(zdt.toString({ timeZoneName: "critical", offset: "never" })); // '2021-08-01T12:34:56[!America/New_York]'

Specifications

Specification
Temporal
# sec-temporal.zoneddatetime.prototype.tostring

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
toString
Chrome – Full support
Chrome 144 (Release date: 2026-01-13)
footnote Full support
Edge – Full support
Edge 144 (Release date: 2026-01-21)
footnote Full support
Firefox – Full support
Firefox 139 (Release date: 2025-05-27)
footnote Full support
Opera – Full support
Opera 128 (Release date: 2026-02-26)
footnote Full support
Safari – No support
Safari
footnote
footnote See bug 223166
Chrome Android – Full support
Chrome Android 144 (Release date: 2026-01-13)
footnote Full support
Firefox for Android – Full support
Firefox for Android 139 (Release date: 2025-05-27)
footnote Full support
Opera Android – Full support
Opera Android 95 (Release date: 2026-02-11)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote
footnote See bug 223166
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Full support
WebView Android 144 (Release date: 2026-01-13)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote
footnote See bug 223166
Bun – No support
Bun
footnote No support
Deno – Full support
Deno 2.7 (Release date: 2026-02-25)
footnote Full support
Node.js – No support
Node.js
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

See also