Temporal.PlainMonthDay.prototype.equals()
equals()
方法是
实例的一个方法,如果此月份-日期在值上与另一个(可通过 Temporal.PlainMonthDay
Temporal.PlainMonthDay.from()
转换的表单)月份-日期等价,则返回 true
,否则返回 false
。它们会同时根据其底层的 ISO 日期值和日历进行比较。
注意: PlainMonthDay
对象会跟踪一个引用的 ISO 年份,该年份也用于比较。此年份在使用 Temporal.PlainMonthDay.from()
方法时会自动设置,但也可以使用 Temporal.PlainMonthDay()
构造函数手动设置,这会导致两个等价的月份-日期因引用年份不同而被视为不同。因此,您应该避免直接使用构造函数,而应优先使用 from()
方法。
语法
js
equals(other)
参数
其他
-
一个表示要比较的其他月份-日期的字符串、对象或
Temporal.PlainMonthDay
实例。它将使用与Temporal.PlainMonthDay.from()
相同的算法转换为Temporal.PlainMonthDay
对象。
返回值
如果此月份-日期在日期值和日历上均等于 other
,则返回 true
,否则返回 false
。
示例
使用 equals()
js
const md1 = Temporal.PlainMonthDay.from("2021-08-01");
const md2 = Temporal.PlainMonthDay.from({ year: 2020, month: 8, day: 1 }); // Year doesn't matter
console.log(md1.equals(md2)); // true
const md3 = Temporal.PlainMonthDay.from("2021-08-01[u-ca=japanese]");
console.log(md1.equals(md3)); // false
const md4 = Temporal.PlainMonthDay.from("2021-08-02");
console.log(md1.equals(md4)); // false
规范
规范 |
---|
Temporal # sec-temporal.plainmonthday.prototype.equals |
浏览器兼容性
加载中…