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