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

浏览器兼容性

另见