Temporal.PlainTime.prototype.until()
until()
方法属于 Temporal.PlainTime
实例,它返回一个新的 Temporal.Duration
对象,表示从当前时间到另一个时间(可由 Temporal.PlainTime.from()
转换)的时间差。如果另一个时间在当前时间之后,则时间差为正;如果之前,则为负。
此方法执行 other - this
。要执行 this - other
,请使用 since()
方法。
语法
js
until(other)
until(other, options)
参数
其他
-
一个字符串、对象或
Temporal.PlainTime
实例,表示要从中减去当前时间的另一个时间。它使用与Temporal.PlainTime.from()
相同的算法转换为Temporal.PlainTime
对象。它必须与this
具有相同的日历。 options
可选-
与
since()
相同的选项。
返回值
一个新的 Temporal.Duration
对象,表示从当前时间 *到* other
的时间差。如果 other
在当前时间之后,则时间差为正;如果之前,则为负。
异常
RangeError
-
如果任何选项无效,则抛出。
示例
使用 until()
js
const lunchTime = Temporal.PlainTime.from("12:30:00");
const now = Temporal.Now.plainTimeISO();
const duration = now.until(lunchTime);
console.log(`It will be ${duration.toLocaleString("en-US")} until lunch`);
// Example output: "It will be 3 hr, 42 min, 21 sec, 343 ms, 131 μs, 718 ns until lunch"
更多示例,请参阅 since()
。
规范
规范 |
---|
Temporal # sec-temporal.plaintime.prototype.until |
浏览器兼容性
加载中…