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