Vasyl Boroviak
Vasyl Boroviak

Reputation: 6128

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

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 = ... ?

Upvotes: 1

Views: 501

Answers (1)

Vasyl Boroviak
Vasyl Boroviak

Reputation: 6128

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

Upvotes: 1

Related Questions