Intl.DurationFormat
Baseline 2025Newly 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 die sprachsensitive Formatierung 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 Lokalisierungen enthält, die unterstützt werden, ohne auf die Standard-Lokalisierung der Laufzeitumgebung zurückgreifen 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.DurationFormat
-Instanzen ist der Anfangswert derIntl.DurationFormat
-Konstruktor. 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 gemäß der Lokalisierung und den Formatierungsoptionen dieses
DurationFormat
-Objekts formatiert. Intl.DurationFormat.prototype.formatToParts()
-
Gibt ein
Array
von Objekten zurück, die die formatierte Dauer in Teilen darstellen. Intl.DurationFormat.prototype.resolvedOptions()
-
Gibt ein neues Objekt mit Eigenschaften zurück, die die bei der Initialisierung des Objekts ermittelten Lokalisierungs- und Formatierungsoptionen widerspiegeln.
Beispiele
Verwendung von Intl.DurationFormat
Die folgenden Beispiele zeigen, wie Sie das Intl.DurationFormat
-Objekt verwenden, um ein Dauerobjekt mit verschiedenen Lokalisierungen 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);
// "1h 46min 40s"
Spezifikationen
Specification |
---|
Intl.DurationFormat # durationformat-objects |