Temporal.Instant.prototype.until()
until()
方法是 Temporal.Instant
实例的,它返回一个新的 Temporal.Duration
对象,该对象表示从当前时间点到另一个时间点的持续时间(可以被 Temporal.Instant.from()
转换)。如果另一个时间点在当前时间点之后,则持续时间为正;如果在此之前,则为负。
此方法执行 other - this
。要执行 this - other
,请使用 since()
方法。
语法
js
until(other)
until(other, options)
参数
其他
-
一个字符串或一个
Temporal.Instant
实例,表示要从中减去当前时间点的那个时间点。它使用与Temporal.Instant.from()
相同的算法转换为Temporal.Instant
对象。 options
可选-
与
since()
相同的选项。
返回值
一个新的 Temporal.Duration
对象,表示从当前时间点到 other
的持续时间。如果 other
在当前时间点之后,则持续时间为正;如果在此之前,则为负。
异常
RangeError
-
如果任何选项无效,则抛出。
示例
使用 until()
js
const launch = Temporal.Instant.fromEpochMilliseconds(2051222400000);
const now = Temporal.Now.instant();
const duration = now.until(launch, { smallestUnit: "minutes" });
console.log(`It will be ${duration.toLocaleString("en-US")} until the launch`);
更多示例,请参阅 since()
。
规范
规范 |
---|
Temporal # sec-temporal.instant.prototype.until |
浏览器兼容性
加载中…