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 actually being 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: How to Use JavaScript Intl DateTimeFormat resolvedOptions() 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() Method

JavaScript Intl DateTimeFormat formatRange() Method

JavaScript Intl DateTimeFormat formatRangeToParts() Method

JavaScript Intl DateTimeFormat supportedLocalesOf() Method

JavaScript Intl DateTimeFormat formatToParts() Method

Leave a Comment