Temporal.Instant.prototype.until()

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Phương thức until() của các instance Temporal.Instant trả về một đối tượng Temporal.Duration mới biểu diễn khoảng thời gian từ instant này đến một instant khác (ở dạng có thể chuyển đổi bởi Temporal.Instant.from()). Khoảng thời gian là dương nếu instant kia đến sau instant này, và âm nếu trước.

Phương thức này thực hiện other - this. Để thực hiện this - other, sử dụng phương thức since().

Cú pháp

js
until(other)
until(other, options)

Tham số

other

Một chuỗi hoặc instance Temporal.Instant biểu diễn một instant để trừ instant này đi. Nó được chuyển đổi thành đối tượng Temporal.Instant bằng cùng thuật toán như Temporal.Instant.from().

options Optional

Các tùy chọn giống như since().

Giá trị trả về

Một đối tượng Temporal.Duration mới biểu diễn khoảng thời gian từ instant này cho đến other. Khoảng thời gian là dương nếu other đến sau instant này, và âm nếu trước.

Ngoại lệ

RangeError

Được ném ra nếu bất kỳ tùy chọn nào không hợp lệ.

Ví dụ

Sử dụng until()

js
const launch = Temporal.Instant.fromEpochMilliseconds(2051222400000);
const now = Temporal.Now.instant();
const duration = now.until(launch, { smallestUnit: "minutes" });
console.log(`It will be ${duration.toLocaleString("en-US")} until the launch`);

Xem thêm các ví dụ trong since().

Đặc tả

Specification
Temporal
# sec-temporal.instant.prototype.until

Tương thích trình duyệt

Xem thêm