This feature is not Baseline because it does not work in some of the most widely-used browsers.
The Temporal.Duration() constructor creates Temporal.Duration objects.
This constructor allows you to create instances by directly supplying the underlying data. Like all other Temporal classes, you should usually construct Temporal.Duration objects using the Temporal.Duration.from() static method, which can handle a variety of input types.
new Temporal.Duration() new Temporal.Duration(years) new Temporal.Duration(years, months) new Temporal.Duration(years, months, weeks) new Temporal.Duration(years, months, weeks, days) new Temporal.Duration(years, months, weeks, days, hours) new Temporal.Duration(years, months, weeks, days, hours, minutes) new Temporal.Duration(years, months, weeks, days, hours, minutes, seconds) new Temporal.Duration(years, months, weeks, days, hours, minutes, seconds, milliseconds) new Temporal.Duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds) new Temporal.Duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds)
years OptionalNumber of years, or undefined (which is treated as 0).
months OptionalNumber of months, or undefined (which is treated as 0).
weeks OptionalNumber of weeks, or undefined (which is treated as 0).
days OptionalNumber of days, or undefined (which is treated as 0).
hours OptionalNumber of hours, or undefined (which is treated as 0).
minutes OptionalNumber of minutes, or undefined (which is treated as 0).
seconds OptionalNumber of seconds, or undefined (which is treated as 0).
milliseconds OptionalNumber of milliseconds, or undefined (which is treated as 0).
microseconds OptionalNumber of microseconds, or undefined (which is treated as 0).
nanoseconds OptionalNumber of nanoseconds, or undefined (which is treated as 0).
A new Temporal.Duration object, possibly unbalanced, with the specified components.
RangeErrorThrown in one of the following cases:
const d = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); console.log(d.toString()); // "P1Y2M3W4DT5H6M7.00800901S"
| Specification |
|---|
| Temporal> # sec-temporal-duration-constructor> |
| 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 | |
Duration |
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/Duration