Temporal.Instant.prototype.equals()
equals() 方法用於 Temporal.Instant 例項,如果此時間點在值上與另一個時間點(可透過 Temporal.Instant.from() 轉換)等效,則返回 true,否則返回 false。它們透過其 epochNanoseconds 進行比較。它等同於 Temporal.Instant.compare(this, other) === 0。
語法
js
equals(other)
引數
其他-
一個字串或一個
Temporal.Instant例項,表示要比較的另一個時間點。它使用與Temporal.Instant.from()相同的演算法轉換為Temporal.Instant物件。
返回值
如果此時間點與 other 按納秒相等,則返回 true,否則返回 false。
示例
使用 equals()
js
const instant1 = Temporal.Instant.from("2021-08-01T12:34:56Z");
const instant2 = Temporal.Instant.fromEpochMilliseconds(1627821296000);
console.log(instant1.equals(instant2)); // true
規範
| 規範 |
|---|
| Temporal # sec-temporal.instant.prototype.equals |
瀏覽器相容性
載入中…