This feature is not Baseline because it does not work in some of the most widely-used browsers.
The Temporal.Duration.from() static method creates a new Temporal.Duration object from another Temporal.Duration object, an object with duration properties, or an ISO 8601 string.
Temporal.Duration.from(info)
infoOne of the following:
A Temporal.Duration instance, which creates a copy of the instance.
An ISO 8601 string representing a duration.
An object containing at least one of the following properties (in the order they are retrieved and validated):
Each property should contain an integer number value. The resulting duration must not have mixed signs, so all of these properties must have the same sign (or zero). Missing properties are treated as zero.
A new Temporal.Duration object, possibly unbalanced, with the specified components.
RangeErrorThrown in one of the following cases:
info object is not an integer (including non-finite values).TypeErrorThrown in one of the following cases:
info is not an object or a string.info object are undefined.const d1 = Temporal.Duration.from({ hours: 1, minutes: 30 });
console.log(d1.toString()); // "PT1H30M"
const d2 = Temporal.Duration.from({ months: 1, days: 2 });
console.log(d2.toString()); // "P1M2D"
// Uncommon because unbalanced, but valid
const unbalanced = Temporal.Duration.from({
hours: 100,
minutes: 100,
seconds: 100,
});
console.log(unbalanced.toString()); // "PT100H100M100S"
const neg = Temporal.Duration.from({ hours: -1, minutes: -30 });
console.log(neg.toString()); // "-PT1H30M"
const d = Temporal.Duration.from("P1Y2M3W4DT5H6M7.00800901S");
console.log(d.hours); // 5
const d1 = Temporal.Duration.from({ hours: 1, minutes: 30 });
const d2 = Temporal.Duration.from(d1);
console.log(d2.toString()); // "PT1H30M"
| Specification |
|---|
| Temporal> # sec-temporal.duration.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/Duration/from