Intl.DurationFormat
Baseline
2025
Newly available
Since March 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Das Intl.DurationFormat-Objekt ermöglicht sprachsensitives Formatieren von Zeitdauern.
Konstruktor
Intl.DurationFormat()-
Erstellt ein neues
Intl.DurationFormat-Objekt.
Statische Methoden
Intl.DurationFormat.supportedLocalesOf()-
Gibt ein Array zurück, das die der angegebenen Sprachcodes enthält, die unterstützt werden, ohne auf die Standard-Spracheinstellung der Laufzeitumgebung zurückfallen zu müssen.
Instanz-Eigenschaften
Diese Eigenschaften sind auf Intl.DurationFormat.prototype definiert und werden von allen Intl.DurationFormat Instanzen geteilt.
Intl.DurationFormat.prototype.constructor-
Die Konstruktorfunktion, die das Instanzobjekt erstellt hat. Für
Intl.DurationFormatInstanzen ist der Anfangswert derIntl.DurationFormatKonstruktor. Intl.DurationFormat.prototype[Symbol.toStringTag]-
Der Anfangswert der
[Symbol.toStringTag]-Eigenschaft ist der String"Intl.DurationFormat". Diese Eigenschaft wird inObject.prototype.toString()verwendet.
Instanz-Methoden
Intl.DurationFormat.prototype.format()-
Getter-Funktion, die eine Dauer entsprechend der Sprach- und Formatierungsoptionen dieses
DurationFormat-Objekts formatiert. Intl.DurationFormat.prototype.formatToParts()-
Gibt ein
Arrayvon Objekten zurück, die die formatierte Dauer in Teilen repräsentieren. Intl.DurationFormat.prototype.resolvedOptions()-
Gibt ein neues Objekt mit Eigenschaften zurück, die die Spracheinstellungen und Formatierungsoptionen widerspiegeln, die während der Initialisierung des Objekts berechnet wurden.
Beispiele
>Verwendung von Intl.DurationFormat
Die folgenden Beispiele zeigen, wie das Intl.DurationFormat-Objekt verwendet wird, um ein Zeitdauer-Objekt mit verschiedenen Sprachen und Stilen zu formatieren.
const duration = {
hours: 1,
minutes: 46,
seconds: 40,
};
// With style set to "long" and locale "fr-FR"
new Intl.DurationFormat("fr-FR", { style: "long" }).format(duration);
// "1 heure, 46 minutes et 40 secondes"
// With style set to "short" and locale "en"
new Intl.DurationFormat("en", { style: "short" }).format(duration);
// "1 hr, 46 min and 40 sec"
// With style set to "narrow" and locale "pt"
new Intl.DurationFormat("pt", { style: "narrow" }).format(duration);
// "1 h 46 min 40 s"
Spezifikationen
| Specification |
|---|
| Intl.DurationFormat> # durationformat-objects> |
Browser-Kompatibilität
Loading…