Temporal.Instant.fromEpochMilliseconds()

Limited availability

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

Experimentell: Dies ist eine experimentelle Technologie
Überprüfen Sie die Browser-Kompatibilitätstabelle sorgfältig vor der Verwendung auf produktiven Webseiten.

Die statische Methode Temporal.Instant.fromEpochMilliseconds() erstellt ein neues Temporal.Instant-Objekt aus der Anzahl der Millisekunden seit der Unix-Epoche (Mitternacht zu Beginn des 1. Januars 1970, UTC).

Um ein Date-Objekt in ein Temporal.Instant-Objekt zu konvertieren, verwenden Sie stattdessen Date.prototype.toTemporalInstant().

Syntax

js
Temporal.Instant.fromEpochMilliseconds(epochMilliseconds)

Parameter

epochMilliseconds

Eine Zahl, die die Anzahl der Millisekunden seit der Unix-Epoche darstellt. Intern wird sie in ein BigInt umgewandelt und mit 1e6 multipliziert, um die Anzahl der Nanosekunden zu erhalten.

Rückgabewert

Ein neues Temporal.Instant-Objekt, das den durch epochMilliseconds angegebenen Zeitpunkt repräsentiert.

Ausnahmen

RangeError

Wird in einem der folgenden Fälle ausgelöst:

  • epochMilliseconds kann nicht in ein BigInt umgewandelt werden (z. B. ist es keine ganze Zahl).
  • epochMilliseconds liegt nicht im darstellbaren Bereich, der ±108 Tage (etwa ±273.972,6 Jahre) von der Unix-Epoche entfernt ist.

Beispiele

Verwendung von 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

Spezifikationen

Specification
Temporal proposal
# sec-temporal.instant.fromepochmilliseconds

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
fromEpochMilliseconds
Experimental

Legend

Tip: you can click/tap on a cell for more information.

In development. Supported in a pre-release version.
In development. Supported in a pre-release version.
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.
User must explicitly enable this feature.

Siehe auch