Temporal.PlainTime.prototype.equals()
equals()
方法是 Temporal.PlainTime
实例的一个方法,如果当前时间与另一个时间(可以通过 Temporal.PlainTime.from()
转换的形式)在值上相等,则返回 true
,否则返回 false
。它们是根据时间值进行比较的。这等同于 Temporal.PlainTime.compare(this, other) === 0
。
语法
js
equals(other)
参数
其他
-
一个字符串、一个对象或一个
Temporal.PlainTime
实例,表示要比较的另一个时间。它使用与Temporal.PlainTime.from()
相同的算法转换为Temporal.PlainTime
对象。
返回值
如果当前时间和 other
在其时间值和日历上都相等,则返回 true
,否则返回 false
。
示例
使用 equals()
js
const time1 = Temporal.PlainTime.from("12:34:56");
const time2 = Temporal.PlainTime.from({ hour: 12, minute: 34, second: 56 });
console.log(time1.equals(time2)); // true
const time3 = Temporal.PlainTime.from("00:34:56");
console.log(time1.equals(time3)); // false
规范
规范 |
---|
Temporal # sec-temporal.plaintime.prototype.equals |
浏览器兼容性
加载中…