Temporal.Instant.prototype.epochMilliseconds
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Thuộc tính accessor epochMilliseconds của các thực thể Temporal.Instant trả về một số nguyên biểu diễn số mili giây đã trôi qua kể từ epoch Unix (nửa đêm đầu ngày 1 tháng 1 năm 1970, UTC) đến instant này. Nó tương đương với việc chia epochNanoseconds cho 1e6 và làm tròn xuống kết quả.
Set accessor của epochMilliseconds là undefined. Bạn không thể thay đổi thuộc tính này trực tiếp. Để tạo một đối tượng Temporal.Instant mới với giá trị epochMilliseconds mới mong muốn, hãy sử dụng phương thức tĩnh Temporal.Instant.fromEpochMilliseconds() thay thế.
Ví dụ
>Sử dụng epochMilliseconds
const instant = Temporal.Instant.from("2021-08-01T12:34:56.789Z");
console.log(instant.epochMilliseconds); // 1627821296789
const instant2 = Temporal.Instant.from("1969-08-01T12:34:56.789Z");
console.log(instant2.epochMilliseconds); // -13173903211
Thay đổi epochMilliseconds
Đây là phương thức cho phép bạn di chuyển bất kỳ lượng thời gian nào:
const instant = Temporal.Instant.from("2021-08-01T12:34:56.789Z");
const instant1hourLater = instant.add({ hours: 1 });
console.log(instant1hourLater.epochMilliseconds); // 1627824896789
Nếu bạn đã biết sự thay đổi theo mili giây, bạn cũng có thể trực tiếp xây dựng một đối tượng Temporal.Instant mới:
const instant = Temporal.Instant.from("2021-08-01T12:34:56.789Z");
const instant1hourLater = Temporal.Instant.fromEpochMilliseconds(
instant.epochMilliseconds + 3600000,
);
console.log(instant1hourLater.epochMilliseconds); // 1627824896789
Đặc tả
| Specification |
|---|
| Temporal> # sec-get-temporal.instant.prototype.epochmilliseconds> |