Temporal.Duration.from()

Limited availability

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.

Syntax

js
Temporal.Duration.from(info)

Parameters

info

One of the following:

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 recognized properties in the info object 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.
TypeError

Thrown in one of the following cases:

  • info is not an object or a string.
  • All of the recognized properties in the info object are undefined.

Examples

Creating a duration from an object

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

Creating a duration from a string

js
const d = Temporal.Duration.from("P1Y2M3W4DT5H6M7.00800901S");
console.log(d.hours); // 5

Creating a duration from another duration

js
const d1 = Temporal.Duration.from({ hours: 1, minutes: 30 });
const d2 = Temporal.Duration.from(d1);
console.log(d2.toString()); // "PT1H30M"

Specifications

Specification
Temporal
# sec-temporal.duration.from

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