Loading lesson path
The Temporal.Duration Object
Temporal.Duration object represents a length of time.
7 days and 1 hour.
Temporal.Duration object includes these properties
years, months, weeks, days, hours, minutes, seconds, milliseconds, and nanoseconds.
Formula
// Create a duration using an object literal const duration = Temporal.Duration.from({days:7, hours:2});Durations can be created from and converted to
(e.g."P7DT2H"). It has the following form (spaces are added for readability): +P nY nM nW nD T nH nM nS For example, "P3Y6M4DT12H30M5S" represents a duration of "three years, six months, four days, twelve hours, thirty minutes, and five seconds".
±
Formula
Optional positive/negative duration (default is +).P Duration designator (for period) nY
T Time designator (precedes time components) nH
You can create a Temporal.Duration object using the new constructor with integer parameters.
Create a duration of 7 days and 2 hours.
const duration = new Temporal.Duration(0, 0, 0, 7, 2);