Intl.RelativeTimeFormat.prototype.resolvedOptions()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2020.
Die Methode resolvedOptions() von Intl.RelativeTimeFormat-Instanzen gibt ein neues Objekt mit Eigenschaften zurück, die die während der Initialisierung dieses RelativeTimeFormat-Objekts berechneten Optionen widerspiegeln.
Probieren Sie es aus
const rtf1 = new Intl.RelativeTimeFormat("en", { style: "narrow" });
const options1 = rtf1.resolvedOptions();
const rtf2 = new Intl.RelativeTimeFormat("es", { numeric: "auto" });
const options2 = rtf2.resolvedOptions();
console.log(`${options1.locale}, ${options1.style}, ${options1.numeric}`);
// Expected output: "en, narrow, always"
console.log(`${options2.locale}, ${options2.style}, ${options2.numeric}`);
// Expected output: "es, long, auto"
Syntax
resolvedOptions()
Parameter
Keine.
Rückgabewert
Ein neues Objekt mit Eigenschaften, die die während der Initialisierung dieses RelativeTimeFormat-Objekts berechneten Optionen widerspiegeln. Das Objekt hat die folgenden Eigenschaften, in der Reihenfolge, in der sie aufgelistet sind:
locale-
Das BCP 47-Sprachtag für das tatsächlich verwendete Gebietsschema, bestimmt durch den Prozess der Locale-Verhandlung. Nur der
nuUnicode-Erweiterungsschlüssel, falls angefordert, kann in der Ausgabe enthalten sein. style-
Der für diese Eigenschaft im
options-Argument bereitgestellte Wert, mit Standardeinstellung, falls erforderlich. Es ist entweder"long","short"oder"narrow". Der Standardwert ist"long". numeric-
Der für diese Eigenschaft im
options-Argument bereitgestellte Wert, mit Standardeinstellung, falls erforderlich. Es ist entweder"always"oder"auto". Der Standardwert ist"always". numberingSystem-
Der für diese Eigenschaft im
options-Argument bereitgestellte Wert oder mithilfe des Unicode-Erweiterungsschlüssels"nu", mit Standardeinstellung, falls erforderlich. Es ist ein unterstütztes Zahlensystem für dieses Gebietsschema. Der Standardwert ist gebietsschemaabhängig.
Beispiele
>Verwendung der Methode resolvedOptions()
const de = new Intl.RelativeTimeFormat("de-DE");
const usedOptions = de.resolvedOptions();
usedOptions.locale; // "de-DE"
usedOptions.style; // "long"
usedOptions.numeric; // "always"
usedOptions.numberingSystem; // "latn"
Spezifikationen
| Specification |
|---|
| ECMAScript® 2026 Internationalization API Specification> # sec-intl.relativetimeformat.prototype.resolvedoptions> |
Browser-Kompatibilität
Loading…