Temporal.Instant.fromEpochNanoseconds()

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.Instant.fromEpochNanoseconds() tạo một đối tượng Temporal.Instant mới từ số nano giây kể từ epoch Unix (nửa đêm đầu ngày 1 tháng 1 năm 1970, UTC).

Để chuyển đổi đối tượng Date sang đối tượng Temporal.Instant, hãy sử dụng Date.prototype.toTemporalInstant() thay thế.

Cú pháp

js
Temporal.Instant.fromEpochNanoseconds(epochNanoseconds)

Tham số

epochNanoseconds

Một BigInt biểu diễn số nano giây kể từ epoch Unix.

Giá trị trả về

Một đối tượng Temporal.Instant mới biểu diễn thời điểm được chỉ định bởi epochNanoseconds.

Ngoại lệ

RangeError

Được ném nếu epochNanoseconds không nằm trong phạm vi có thể biểu diễn, là ±108 ngày, hoặc khoảng ±273.972,6 năm, từ epoch Unix.

Ví dụ

Sử dụng Temporal.Instant.fromEpochNanoseconds()

js
const instant = Temporal.Instant.fromEpochNanoseconds(0n);
console.log(instant.toString()); // 1970-01-01T00:00:00Z
const vostok1Liftoff =
  Temporal.Instant.fromEpochNanoseconds(-275248380000000000n);
console.log(vostok1Liftoff.toString()); // 1961-04-12T06:07:00Z
const sts1Liftoff = Temporal.Instant.fromEpochNanoseconds(355924804000000000n);
console.log(sts1Liftoff.toString()); // 1981-04-12T12:00:04Z

Đặc tả

Specification
Temporal
# sec-temporal.instant.fromepochnanoseconds

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

Xem thêm