Temporal.Instant.fromEpochMilliseconds()
Khả dụng hạn chế
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.fromEpochMilliseconds() tạo một đối tượng Temporal.Instant mới từ số mili 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.fromEpochMilliseconds(epochMilliseconds)
Tham số
epochMilliseconds-
Một số biểu diễn số mili giây kể từ epoch Unix. Trong nội bộ, nó được chuyển đổi thành BigInt và nhân với
1e6để lấy số nano giây.
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 epochMilliseconds.
Ngoại lệ
RangeError-
Được ném trong một trong các trường hợp sau:
epochMillisecondskhông thể chuyển đổi thành BigInt (ví dụ: không phải số nguyên).epochMillisecondskhô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.fromEpochMilliseconds()
js
const instant = Temporal.Instant.fromEpochMilliseconds(0);
console.log(instant.toString()); // 1970-01-01T00:00:00Z
const vostok1Liftoff = Temporal.Instant.fromEpochMilliseconds(-275248380000);
console.log(vostok1Liftoff.toString()); // 1961-04-12T06:07:00Z
const sts1Liftoff = Temporal.Instant.fromEpochMilliseconds(355924804000);
console.log(sts1Liftoff.toString()); // 1981-04-12T12:00:04Z
Đặc tả
| Thông số kỹ thuật |
|---|
| Temporal> # sec-temporal.instant.fromepochmilliseconds> |