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 resolvedOptions()-Methode 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

js
resolvedOptions()

Parameter

Keine.

Rückgabewert

Ein neues Objekt mit Eigenschaften, die die während der Initialisierung dieses RelativeTimeFormat-Objekts berechneten Optionen widerspiegeln. Das Objekt besitzt die folgenden Eigenschaften, in der Reihenfolge, in der sie aufgelistet sind:

locale

Das BCP 47-Sprach-Tag für die tatsächlich verwendete Locale, bestimmt durch den Locale-Aushandlungsprozess. Nur der nu-Unicode-Erweiterungsschlüssel, falls angefordert, kann in der Ausgabe enthalten sein.

style

Der Wert, der für diese Eigenschaft im options-Argument angegeben wurde, mit Standardeinstellungen, falls erforderlich. Es ist entweder "long", "short" oder "narrow". Der Standardwert ist "long".

numeric

Der Wert, der für diese Eigenschaft im options-Argument angegeben wurde, mit Standardeinstellungen, falls erforderlich. Es ist entweder "always" oder "auto". Der Standardwert ist "always".

numberingSystem

Der Wert, der für diese Eigenschaft im options-Argument angegeben wurde, oder mithilfe des Unicode-Erweiterungsschlüssels "nu", mit Standardeinstellungen, falls erforderlich. Es ist ein unterstütztes Nummerierungssystem für diese Locale. Der Standardwert ist von der Locale abhängig.

Beispiele

Verwendung der resolvedOptions()-Methode

js
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® 2025 Internationalization API Specification
# sec-intl.relativetimeformat.prototype.resolvedoptions

Browser-Kompatibilität

BCD tables only load in the browser

Siehe auch