Temporal.ZonedDateTime.prototype.epochNanoseconds

Khả dụng hạn chế

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

Thuộc tính accessor epochNanoseconds của các thực thể Temporal.ZonedDateTime trả về một BigInt biểu thị số nano giây đã trôi qua kể từ Unix epoch (nửa đêm đầu ngày 1 tháng 1 năm 1970, UTC) cho đến thời điểm này.

Set accessor của epochNanosecondsundefined. Bạn không thể thay đổi thuộc tính này trực tiếp. Để tạo đối tượng Temporal.ZonedDateTime mới với giá trị epochNanoseconds mong muốn, hãy sử dụng hàm tạo new Temporal.ZonedDateTime() thay thế.

Một thời điểm chỉ có thể biểu thị ±108 ngày (khoảng ±273.972,6 năm) quanh epoch, tức là ±8,64e21 nano giây. Việc đặt epochNanoseconds vượt quá giới hạn này sẽ ném ra RangeError.

Ví dụ

Sử dụng epochNanoseconds

js
const zdt = Temporal.ZonedDateTime.from("2021-08-01T12:34:56.789Z[UTC]");
console.log(zdt.epochNanoseconds); // 1627821296789000000n

const zdt2 = Temporal.ZonedDateTime.from("1969-08-01T12:34:56.789Z[UTC]");
console.log(zdt2.epochNanoseconds); // -13173903211000000n

Tạo đối tượng ZonedDateTime từ giá trị epochNanoseconds

Bạn có thể tạo đối tượng Temporal.ZonedDateTime từ giá trị epochNanoseconds bằng hàm tạo Temporal.ZonedDateTime().

js
const epochNanoseconds = 1627821296789000000n;
const zdt = new Temporal.ZonedDateTime(epochNanoseconds, "UTC");
console.log(zdt.toString()); // 2021-08-01T12:34:56.789+00:00[UTC]

Thông số kỹ thuật

Thông số kỹ thuật
Temporal
# sec-get-temporal.zoneddatetime.prototype.epochnanoseconds

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

Xem thêm