Temporal.PlainDateTime.prototype.equals()
equals() 方法用於 Temporal.PlainDateTime 例項,如果此日期時間與另一個日期時間(可透過 Temporal.PlainDateTime.from() 轉換)在值上等效,則返回 true,否則返回 false。它們會同時比較它們的日期和時間值以及它們的日曆,因此來自不同日曆的兩個日期時間可能透過 Temporal.PlainDateTime.compare() 視為相等,但透過 equals() 則不相等。
語法
js
equals(other)
引數
其他-
一個字串、一個物件或一個
Temporal.PlainDateTime例項,表示要比較的另一個日期時間。它使用與Temporal.PlainDateTime.from()相同的演算法轉換為Temporal.PlainDateTime物件。
返回值
如果此日期時間與其 other 在日期/時間值和日曆上都相等,則為 true,否則為 false。
示例
使用 equals()
js
const dt1 = Temporal.PlainDateTime.from("2021-08-01");
const dt2 = Temporal.PlainDateTime.from({ year: 2021, month: 8, day: 1 });
console.log(dt1.equals(dt2)); // true
const dt3 = Temporal.PlainDateTime.from("2021-08-01[u-ca=japanese]");
console.log(dt1.equals(dt3)); // false
const dt4 = Temporal.PlainDateTime.from("2021-08-01T01:00:00");
console.log(dt1.equals(dt4)); // false
規範
| 規範 |
|---|
| Temporal # sec-temporal.plaindatetime.prototype.equals |
瀏覽器相容性
載入中…