Temporal.Duration.prototype.negated()

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

實驗性: 這是一項實驗性技術
在生產中使用此技術之前,請仔細檢查瀏覽器相容性表格

Temporal.Duration 例項的 negated() 方法返回一個新的 Temporal.Duration 物件,該物件的負值是此持續時間(所有欄位保持相同的絕對值,但符號反轉)。

語法

js
negated()

引數

無。

返回值

一個新的 Temporal.Duration 物件,其中所有欄位的絕對值與此持續時間相同,但符號反轉(正欄位變為負,反之亦然)。

示例

使用 negated()

js
const d1 = Temporal.Duration.from({ hours: 1, minutes: 30 });
const d2 = Temporal.Duration.from({ hours: -1, minutes: -30 });

console.log(d1.negated().toString()); // "-PT1H30M"
console.log(d2.negated().toString()); // "PT1H30M"

規範

規範
Temporal
# sec-temporal.duration.prototype.negated

瀏覽器相容性

另見