This feature is not Baseline because it does not work in some of the most widely-used browsers.
The Temporal.PlainTime.from() static method creates a new Temporal.PlainTime object from another Temporal.PlainTime object, an object with time properties, or an RFC 9557 string.
Temporal.PlainTime.from(info) Temporal.PlainTime.from(info, options)
infoOne of the following:
A Temporal.PlainTime instance, which creates a copy of the instance.
A Temporal.PlainDateTime instance, which provides the time in the same fashion as Temporal.PlainDateTime.prototype.toPlainTime().
A Temporal.ZonedDateTime instance, which provides the time in the same fashion as Temporal.ZonedDateTime.prototype.toPlainTime().
An RFC 9557 string containing a time.
An object containing at least one of the following properties (in the order they are retrieved and validated):
They are truncated to be integers. Out-of-range values are handled by the overflow option.
options OptionalAn object containing the following property:
overflow OptionalA string specifying the behavior when a time component is out of range (when using the object info). Possible values are:
"constrain" (default)The time component is clamped to the valid range.
"reject"A RangeError is thrown if the time component is out of range.
A new Temporal.PlainTime object, representing the time specified by info.
TypeErrorThrown in one of the following cases:
info is not an object with at least one recognized property or a string.options is not an object or undefined.RangeErrorThrown if the provided numerical properties are out of range, and options.overflow is set to "reject".
const t1 = Temporal.PlainTime.from({ hour: 0 });
console.log(t1.toString()); // "00:00:00"
const t2 = Temporal.PlainTime.from({ hour: 12, minute: 34, second: 56 });
console.log(t2.toString()); // "12:34:56"
const t3 = Temporal.PlainTime.from({
hour: 12,
minute: 34,
second: 56,
millisecond: 123,
microsecond: 456,
nanosecond: 789,
});
console.log(t3.toString()); // "12:34:56.123456789"
By default, out-of-range values are clamped to the valid range:
const t1 = Temporal.PlainTime.from({ hour: 25 });
console.log(t1.toString()); // "23:00:00"
const t2 = Temporal.PlainTime.from({ hour: 25, minute: 60 });
console.log(t2.toString()); // "23:59:00"
You can change this behavior to throw an error instead:
Temporal.PlainTime.from({ hour: 25 }, { overflow: "reject" });
// RangeError: time value "hour" not in 0..23: 25
const t1 = Temporal.PlainTime.from("12:34:56.123456789");
console.log(t1.toLocaleString("en-US", { timeStyle: "full" }));
// 12:34:56 PM
const dt = Temporal.PlainDateTime.from("2021-07-01T12:00");
const t = Temporal.PlainTime.from(dt);
console.log(t.toString()); // "12:00:00"
const zdt = Temporal.ZonedDateTime.from(
"2021-07-01T00:00+08:00[Asia/Shanghai]",
);
const t2 = Temporal.PlainTime.from(zdt);
console.log(t2.toString()); // "00:00:00"
const t3 = Temporal.PlainTime.from(t);
console.log(t3.toString()); // "12:00:00"
| Specification |
|---|
| Temporal> # sec-temporal.plaintime.from> |
| 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 | |
from |
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/from