Temporal.Now.instant()

Limited availability

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

Phương thức tĩnh Temporal.Now.instant() trả về thời gian hiện tại như là đối tượng Temporal.Instant.

Cú pháp

js
Temporal.Now.instant()

Tham số

Không có.

Giá trị trả về

Một đối tượng Temporal.Instant biểu diễn thời gian hiện tại, với độ chính xác có thể bị giảm.

Ví dụ

Đo thời gian đã trôi qua

Ví dụ sau đo hai thời điểm và tính toán khoảng thời gian giữa chúng, và lấy tổng khoảng thời gian tính bằng mili giây:

js
const start = Temporal.Now.instant();
// Do something that takes time
const end = Temporal.Now.instant();
const duration = end.since(start);
console.log(duration.total("milliseconds"));

Đặc tả

Specification
Temporal
# sec-temporal.now.instant

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

Xem thêm