Temporal.PlainDateTime.prototype.withPlainTime()

Limited availability

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

The withPlainTime() method of Temporal.PlainDateTime instances returns a new Temporal.PlainDateTime object representing this date-time with the time part entirely replaced by the new time (in a form convertible by Temporal.PlainTime.from())

This method will replace all time properties, defaulting to 0 where properties are unspecified. If you only want to replace some of the time properties, use the with() method instead.

Syntax

js
withPlainTime()
withPlainTime(plainTime)

Parameters

plainTime Optional

A string, an object, or a Temporal.PlainTime instance representing the new time. It is converted to a Temporal.PlainTime object using the same algorithm as Temporal.PlainTime.from(). If not specified, the time part is set to 00:00:00.

Return value

A new Temporal.PlainDateTime object, with the date part copied from the original date-time and the time part replaced by the new time.

Examples

Using withPlainTime()

js
const dt = Temporal.PlainDateTime.from("2021-07-01T12:34:56");

// You can pass a string
const newDT = dt.withPlainTime("13:45:00");
console.log(newDT.toString()); // "2021-07-01T13:45:00"

// You can only specify some time properties, and the rest default to 0;
// for the with() method, they would be copied from the original date-time
const newDT2 = dt.withPlainTime({ hour: 13 });
console.log(newDT2.toString()); // "2021-07-01T13:00:00"

// You can pass nothing to set the time to midnight
const newDT3 = dt.withPlainTime();
console.log(newDT3.toString()); // "2021-07-01T00:00:00"

Specifications

Specification
Temporal
# sec-temporal.plaindatetime.prototype.withplaintime

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
withPlainTime
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