This feature is not Baseline because it does not work in some of the most widely-used browsers.
The subtract() method of Temporal.Instant instances returns a new Temporal.Instant object representing this instant moved backward by a given duration (in a form convertible by Temporal.Duration.from()).
If you want to subtract two instants and get a duration, use since() or until() instead.
subtract(duration)
durationA string, an object, or a Temporal.Duration instance representing a duration to subtract from this instant. It is converted to a Temporal.Duration object using the same algorithm as Temporal.Duration.from().
A new Temporal.Instant object representing subtracting duration from this instant. If duration is positive, then the returned instant is earlier than this instant; if duration is negative, then the returned instant is later than this instant.
RangeErrorThrown in one of the following cases:
duration is a calendar duration (it has a non-zero years, months, or weeks), or has a non-zero days, because calendar durations are ambiguous without a calendar and time reference.Subtracting a duration is equivalent to adding its negation, so all the same considerations apply.
const instant = Temporal.Instant.fromEpochMilliseconds(1000);
const duration = Temporal.Duration.from("PT1S"); // One-second duration
const newInstant = instant.subtract(duration);
console.log(newInstant.epochMilliseconds); // 0
For more examples, see add().
| Specification |
|---|
| Temporal> # sec-temporal.instant.prototype.subtract> |
| 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 | |
subtract |
144 | 144 | 139 | No | preview | 144 | 139 | No | No | No | 144 | No | ? | 1.40 | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant/subtract