Temporal.PlainMonthDay.prototype.equals()
equals() 方法是 例項的一個方法,如果此月份-日期在值上與另一個(可透過 Temporal.PlainMonthDayTemporal.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 |
瀏覽器相容性
載入中…