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 |
瀏覽器相容性
載入中…