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