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 |
浏览器兼容性
加载中…