Temporal.PlainDateTime.prototype.toString()
The toString() method of Temporal.PlainDateTime instances returns a string representing this date-time in the RFC 9557 format.
The **`toString()`** method of Temporal.PlainDateTime instances returns a string representing this date-time in the [RFC 9557 format](/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime#rfc_9557_format).
## Syntax
```js-nolint
toString()
toString(options)
```
### Parameters
- `options`
- : An object containing the following property:
- `calendarName`
- : 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.PlainDateTime 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`
- : 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`
- : A string specifying how to round off fractional second digits beyond `fractionalSecondDigits`. See [`Intl.NumberFormat()`](/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#roundingmode). Defaults to `"trunc"`.
- `smallestUnit`
- : 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.
### Return value
A string in the [RFC 9557 format](/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime#rfc_9557_format) representing this date-time. The calendar annotation is 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 dt = Temporal.PlainDateTime.from("2021-08-01T12:34:56");
console.log(dt.toString()); // '2021-08-01T12:34:56'
```
For examples with rounding times, see Temporal.PlainTime.prototype.toString(). For examples with displaying calendars, see Temporal.PlainDate.prototype.toString().
## Specifications
## Browser compatibility
## See also
- Temporal.PlainDateTime
- Temporal.PlainDateTime.from()
- Temporal.PlainDateTime.prototype.toJSON()
- Temporal.PlainDateTime.prototype.toLocaleString()
Cite this
"Temporal.PlainDateTime.prototype.toString()". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime/toString JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy