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

瀏覽器相容性

另見