Open In App

JavaScript Intl DateTimeFormat() Constructor

Last Updated : 04 Apr, 2023
Comments
Improve
Suggest changes
1 Like
Like
Report

JavaScript Intl.DateTimeFormat Constructor is used for creating Intl.DateTimeFormat objects. This constructor can be called with or without the new keyword

Syntax:

Intl.DateTimeFormat(loc, opt)
new Intl.DateTimeFormat(loc, opt)

Parameter: This constructor has two methods and both are optional.

  • loc: This is a String or an array of Strings with the following values allowed:
    • nu: It Specifies the numbering system to be followed
    • ca: It specifies the calendar to be followed
    • hc: It specifies the hour cycle format to be followed
  • opt: This parameter contains other properties such as datestyle, timestyle, dayperiod, era etc.

Returns: This returns a new DateTimeFormat object whose properties differ on whether it is called using new keyword or not.

Below examples illustrate the JavaScript Intl DateTimeFormat() Constructor:

Example 1: In this example, we will create a DateTimeFormat object and use it to format the date object.

Output: The Date variable was formatted using the format method 

4/3/23, 2:11 PM

Example 2: In this example, we will format the Date object using the constructor.

Output:

4, 08

Supported Browsers:

  • Chrome
  • Edge
  • Firefox
  • Opera
  • Safari

We have a complete list of JavaScript Intl methods to check those please go through, the JavaScript Intl Reference article.


Article Tags :

Similar Reads