Temporal.Duration()

Limited availability

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.

Syntax

js
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)

Note: Temporal.Duration() can only be constructed with new. Attempting to call it without new throws a TypeError.

Parameters

years Optional

Number of years, or undefined (which is treated as 0).

months Optional

Number of months, or undefined (which is treated as 0).

weeks Optional

Number of weeks, or undefined (which is treated as 0).

days Optional

Number of days, or undefined (which is treated as 0).

hours Optional

Number of hours, or undefined (which is treated as 0).

minutes Optional

Number of minutes, or undefined (which is treated as 0).

seconds Optional

Number of seconds, or undefined (which is treated as 0).

milliseconds Optional

Number of milliseconds, or undefined (which is treated as 0).

microseconds Optional

Number of microseconds, or undefined (which is treated as 0).

nanoseconds Optional

Number of nanoseconds, or undefined (which is treated as 0).

Return value

A new Temporal.Duration object, possibly unbalanced, with the specified components.

Exceptions

RangeError

Thrown in one of the following cases:

  • Any of the parameters is not an integer (including non-finite values).
  • A calendar unit (years, months, weeks) has an absolute value ≥ 232.
  • The non-calendar part of the duration (days and below), when expressed in seconds, has an absolute value ≥ 253.

Examples

Using Temporal.Duration()

js
const d = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
console.log(d.toString()); // "P1Y2M3W4DT5H6M7.00800901S"

Specifications

Specification
Temporal
# sec-temporal-duration-constructor

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
Duration() constructor
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 – Preview support
Safari TP
footnote
footnote See bug 223166
footnote Preview browser support
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 No support
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 No support
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
In development. Supported in a pre-release version.
In development. Supported in a pre-release version.
No support
No support
See implementation notes.

See also