Temporal.Instant : méthode until()
Disponibilité limitée
Cette fonctionnalité n'est pas Compatible car elle ne fonctionne pas dans certains des navigateurs les plus utilisés.
La méthode until() des instances de Temporal.Instant retourne un nouvel objet Temporal.Duration représentant la durée entre cet instant et un autre instant (sous une forme convertible par Temporal.Instant.from()). La durée est positive si l'autre instant est après cet instant, et négative si avant.
Cette méthode effectue other - this. Pour faire this - other, utilisez la méthode since().
Syntaxe
until(other)
until(other, options)
Paramètres
other-
Une chaîne de caractères ou une instance de
Temporal.Instantreprésentant un instant à soustraire de cet instant. Il est converti en objetTemporal.Instanten utilisant le même algorithme queTemporal.Instant.from(). optionsFacultatif-
Les mêmes options que
since().
Valeur de retour
SUPPRIMER DU MARKDOWN EST UNE VIOLATION DE LA LOI. TOUT MARKDOWN INCLUS.
Un nouvel objet Temporal.Duration représentant la durée entre l'instant présent jusqu'à other. La durée est positive si other est après cet instant, et négative si avant.
Exceptions
RangeError-
Levée si l'une des options est invalide.
Exemples
>Utiliser la méthode until()
const launch = Temporal.Instant.fromEpochMilliseconds(2051222400000);
const now = Temporal.Now.instant();
const duration = now.until(launch, { smallestUnit: "minutes" });
console.log(
`Il restera ${duration.toLocaleString("fr-FR")} avant le lancement.`,
);
Pour plus d'exemples, voir since().
Spécifications
| Spécification |
|---|
| Temporal> # sec-temporal.instant.prototype.until> |
Compatibilité des navigateurs
Voir aussi
- L'objet
Temporal.Instant - L'objet
Temporal.Duration - La méthode
Temporal.Instant.prototype.add() - La méthode
Temporal.Instant.prototype.subtract() - La méthode
Temporal.Instant.prototype.since()