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.Duration
other
的时长。如果 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 |
浏览器兼容性
加载中…