Temporal.Instant.prototype.equals()
Khả dụng hạn chế
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Phương thức equals() của các thực thể Temporal.Instant trả về true nếu instant này tương đương về giá trị với một instant khác (ở dạng có thể chuyển đổi bằng Temporal.Instant.from()), và false nếu không. Chúng được so sánh bằng epochNanoseconds của chúng. Nó tương đương với Temporal.Instant.compare(this, other) === 0.
Cú pháp
js
equals(other)
Tham số
other-
Một chuỗi hoặc thực thể
Temporal.Instantbiểu diễn instant kia cần so sánh. Nó được chuyển đổi thành đối tượngTemporal.Instantbằng cùng thuật toán nhưTemporal.Instant.from().
Giá trị trả về
true nếu instant này bằng other theo nano giây, false nếu không.
Ví dụ
>Sử dụng equals()
js
const instant1 = Temporal.Instant.from("2021-08-01T12:34:56Z");
const instant2 = Temporal.Instant.fromEpochMilliseconds(1627821296000);
console.log(instant1.equals(instant2)); // true
Đặc tả
| Thông số kỹ thuật |
|---|
| Temporal> # sec-temporal.instant.prototype.equals> |