Temporal.PlainYearMonth.prototype.until()
until() 方法用於 例項,返回一個新的 Temporal.PlainYearMonth 物件,該物件表示從當前年月到另一個年月的時長(可由 Temporal.Duration 轉換)。如果另一個年月在當前年月之後,則時長為正;如果在此之前,則時長為負。Temporal.PlainYearMonth.from()
此方法執行 other - this。要執行 this - other,請使用 方法。since()
語法
js
until(other)
until(other, options)
引數
其他-
一個字串、物件或
例項,表示要從中減去當前年月的年月。它使用與Temporal.PlainYearMonth相同的演算法轉換為Temporal.PlainYearMonth.from()Temporal.PlainYearMonth物件。它必須與this具有相同的日曆。 options可選-
與
相同的選項。since()
返回值
一個新的 物件,表示從當前年月 *直到* Temporal.Durationother 的時長。如果 other 在當前年月之後,則時長為正;如果在此之前,則時長為負。
異常
RangeError-
在以下情況之一中丟擲
other的日曆與this不同。- 任何選項無效。
示例
使用 until()
js
const launch = Temporal.PlainYearMonth.from("2035-01");
const now = Temporal.Now.plainDateISO().toPlainYearMonth();
const duration = now.until(launch);
console.log(`It will be ${duration.toLocaleString("en-US")} until the launch`);
更多示例,請參閱 。since()
規範
| 規範 |
|---|
| Temporal # sec-temporal.plainyearmonth.prototype.until |
瀏覽器相容性
載入中…