JavaScript | Intl.DateTimeFormat.prototype.format() Method

The Intl.DateTimeFormat.prototype.format() method is an inbuilt method in JavaScript which is used to format a date according to the locale and formatting options of this Intl.DateTimeFormat object.

Syntax:

dateTimeFormat.format( date )

Parameters: This method accepts a single parameter as mentioned above and described below:

  • date: This parameter holds the date which need to format.

Below examples illustrate the Intl.DateTimeFormat.prototype.format() method in JvaaScript:

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

const Geeks = { weekday: 'long', year: 
'numeric', month: 'long', day: 'numeric' };
const dateformat = new Date(1997, 06, 30);
   
const dateTimeFormat4 = new Intl.DateTimeFormat('hi', Geeks);
console.log(dateTimeFormat4.format(dateformat));
   
const dateTimeFormat2 = new Intl.DateTimeFormat('en-GB', Geeks);
console.log(dateTimeFormat2.format(dateformat));
   
const dateTimeFormat1 = new Intl.DateTimeFormat('sr-RS', Geeks);
console.log(dateTimeFormat1.format(dateformat));
   
const dateTimeFormat3 = new Intl.DateTimeFormat('en-US', Geeks);
console.log(dateTimeFormat3.format(dateformat));

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

var list = [new Date(2012, 08), new Date(2012, 11),
            new Date(2012, 03)];
var geeks = { year: 'numeric', month: 'long' };
  
var dateTime = new Intl.DateTimeFormat('hi', geeks);
var result = list.map(dateTime.format);
console.log(result.join(' <-> '));
  
var dateTime1 = new Intl.DateTimeFormat('tr', geeks);
var result1 = list.map(dateTime1.format);
console.log(result1.join(' ; '));
  
var dateTime2 = new Intl.DateTimeFormat('LT', geeks);
var result2 = list.map(dateTime2.format);
console.log(result2.join(' :: '));

chevron_right


Output:

Supported Browsers: The browsers supported by Intl.DateTimeFormat.prototype.format() method are listed below:

  • Google Chrome
  • Firefox
  • Opera
  • Edge
  • IE
  • Safari

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.