JavaScript Intl DateTimeFormat resolvedOptions() Method

JavaScript Intl DateTimeFormat resolvedOptions method returns a new object with properties reflecting the locale and date and time formatting options computed during initialization of Intl.DateTimeFormat object.

This method can be useful for debugging or understanding what settings are used by a particular DateTimeFormat instance, especially when default values are being filled in for unspecified options.

Syntax

Intl.DateTimeFormat.resolvedOptions()

Parameters

None.

Return Value

 This method returns a new object containing the resolved options.

Example 1: Usage of the method

const dateTimeFormat = new Intl.DateTimeFormat('en-US', {
 year: 'numeric',
 month: 'long',
 day: 'numeric',
 }).resolvedOptions();
 
 console.log(dateTimeFormat);

Output

{
locale: 'en-US',
calendar: 'gregory',
numberingSystem: 'latn',
timeZone: 'Asia/Calcutta',
year: 'numeric',
month: 'long',
day: 'numeric'
}

Example 2: Using a Different Locale

const dateTimeFormat = new Intl.DateTimeFormat('fr-FR', {
 year: 'numeric',
 month: 'short',
 day: '2-digit'
 }).resolvedOptions();
 
 console.log(dateTimeFormat);

Output

{
locale: 'fr-FR',
calendar: 'gregory',
numberingSystem: 'latn',
timeZone: 'Asia/Calcutta',
year: 'numeric',
month: 'short',
day: '2-digit'
}

Browser Compatibility

Chrome 24+ Edge 12+ Firefox 29+ Safari 10+ Opera 15+
Yes Yes Yes Yes Yes

That’s it!

Related posts

JavaScript Int.DateTimeFormat() constructor

JavaScript Intl.DateTimeFormat.format()

JavaScript Intl DateTimeFormat formatRange()

JavaScript Intl DateTimeFormat formatRangeToParts()

JavaScript Intl DateTimeFormat supportedLocalesOf()

JavaScript Intl DateTimeFormat formatToParts()