This feature is not Baseline because it does not work in some of the most widely-used browsers.
The toString() method of Temporal.PlainTime instances returns a string representing this time in the RFC 9557 format.
toString() toString(options)
options OptionalAn object containing some or all of the following properties (in the order they are retrieved and validated):
fractionalSecondDigits OptionalEither 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 OptionalA string specifying how to round off fractional second digits beyond fractionalSecondDigits. See Intl.NumberFormat(). Defaults to "trunc".
smallestUnit OptionalA 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.
A string in the RFC 9557 format representing this time.
RangeErrorThrown if any of the options is invalid.
TypeErrorThrown if options is not an object or undefined.
const time = Temporal.PlainTime.from("12:34:56");
console.log(time.toString()); // '12:34:56'
const time1 = Temporal.PlainTime.from("12:00:00");
console.log(time1.toString()); // '12:00:00'
console.log(time1.toString({ fractionalSecondDigits: 1 })); // '12:00:00.0'
console.log(time1.toString({ smallestUnit: "minute" })); // '12:00'
console.log(time1.toString({ smallestUnit: "nanosecond" })); // '12:00:00.000000000'
const time2 = Temporal.PlainTime.from("12:34:56.123456789");
console.log(time2.toString({ fractionalSecondDigits: 4 })); // '12:34:56.1234'
console.log(
time2.toString({ fractionalSecondDigits: 4, roundingMode: "halfExpand" }),
); // '12:34:56.1235'
| Specification |
|---|
| Temporal> # sec-temporal.plaintime.prototype.tostring> |
| 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 |
144 | 144 | 139 | No | preview | 144 | 139 | No | No | No | 144 | No | ? | 1.40 | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime/toString