Temporal.PlainDate.prototype.equals()
equals() 方法是 Temporal.PlainDate 实例的,它会返回 true,如果此日期在值上等同于另一个日期(可以通过 Temporal.PlainDate.from() 转换为此格式),否则返回 false。它们会同时按其日期值和日历进行比较,因此来自不同日历的两个日期可能在 Temporal.PlainDate.compare() 中被视为相等,但在 equals() 中不一定相等。
语法
js
equals(other)
参数
其他-
一个字符串、一个对象或一个
Temporal.PlainDate实例,表示要比较的另一个日期。它使用与Temporal.PlainDate.from()相同的算法转换为Temporal.PlainDate对象。
返回值
如果此日期在其日期值和日历上都等于 other,则返回 true,否则返回 false。
示例
使用 equals()
js
const date1 = Temporal.PlainDate.from("2021-08-01");
const date2 = Temporal.PlainDate.from({ year: 2021, month: 8, day: 1 });
console.log(date1.equals(date2)); // true
const date3 = Temporal.PlainDate.from("2021-08-01[u-ca=japanese]");
console.log(date1.equals(date3)); // false
const date4 = Temporal.PlainDate.from("2021-08-02");
console.log(date1.equals(date4)); // false
规范
| 规范 |
|---|
| Temporal # sec-temporal.plaindate.prototype.equals |
浏览器兼容性
加载中…