Temporal.Instant.fromEpochMilliseconds()
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The Temporal.Instant.fromEpochMilliseconds()
static method creates a new Temporal.Instant
object from the number of milliseconds since the Unix epoch (midnight at the beginning of January 1, 1970, UTC).
To convert a Date
object to a Temporal.Instant
object, use Date.prototype.toTemporalInstant()
instead.
Syntax
Temporal.Instant.fromEpochMilliseconds(epochMilliseconds)
Parameters
epochMilliseconds
-
A number representing the number of milliseconds since the Unix epoch. Internally, it is converted to a BigInt and multiplied by
1e6
to get the number of nanoseconds.
Return value
A new Temporal.Instant
object representing the instant in time specified by epochMilliseconds
.
Exceptions
RangeError
-
Thrown if
epochMilliseconds
is outside the range of a representable instant, which is ±108 days (±8.64e15 milliseconds, or about ±273,972.6 years), or if it cannot be converted to a BigInt (e.g., not an integer).
Examples
Using Temporal.Instant.fromEpochMilliseconds()
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
Specifications
Specification |
---|
Temporal proposal # sec-temporal.instant.fromepochmilliseconds |
Browser compatibility
BCD tables only load in the browser