How to get Temporal.Duration from two Temporal.Instant in JavaScript?

297 Views Asked by At

I have two Instant objects, and need to get one Duration object. How would I do this in JavaScript?

const start = Temporal.now.instant();
await doLongOperation();
const finish = Temporal.now.instant();

const duration = ... ?
1

There are 1 best solutions below

0
Vasyl Boroviak On

You can use either .until() or .since() methods of a Temporal.Instant object.

Until:

const duration = start.until(finish);

Since:

const duration = finish.since(start);