[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat [Back]  [Original]

Intl.DateTimeFormat - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Intl.DateTimeFormat

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2017 ..

Intl.DateTimeFormat .

In this article

const date = new Date(Date.UTC(2020, 11, 20, 3, 23, 16, 738));
// Results below assume UTC timezone - your results may vary

// Specify default date formatting for language (locale)
console.log(new Intl.DateTimeFormat("en-US").format(date));
// Expected output: "12/20/2020"

// Specify default date formatting for language with a fallback language (in this case Indonesian)
console.log(new Intl.DateTimeFormat(["ban", "id"]).format(date));
// Expected output: "20/12/2020"

// Specify date and time format using "style" options (i.e. full, long, medium, short)
console.log(
  new Intl.DateTimeFormat("en-GB", {
    dateStyle: "full",
    timeStyle: "long",
    timeZone: "Australia/Sydney",
  }).format(date),
);
// Expected output: "Sunday, 20 December 2020 at 14:23:16 GMT+11"

Intl.DateTimeFormat()

Intl.DateTimeFormat.

Intl.DateTimeFormat.supportedLocalesOf()

, , .

Intl.DateTimeFormat.prototype Intl.DateTimeFormat.

Intl.DateTimeFormat.prototype.constructor

-, . Intl.DateTimeFormat Intl.DateTimeFormat.

Intl.DateTimeFormat.prototype[@@toStringTag]

@@toStringTag "Intl.DateTimeFormat". Object.prototype.toString().

Intl.DateTimeFormat.prototype.format()

-, DateTimeFormat.

Intl.DateTimeFormat.prototype.formatRange()

, DateTimeFormat.

Intl.DateTimeFormat.prototype.formatRangeToParts()

, , .

Intl.DateTimeFormat.prototype.formatToParts()

, , .

Intl.DateTimeFormat.prototype.resolvedOptions()

, , .

DateTimeFormat

DateTimeFormat .

js
const date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));

//       ,
//        
console.log(new Intl.DateTimeFormat().format(date));
// "12/19/2012",      en-US    America/Los_Angeles

locales

. , , , (, , ) locales:

js
const date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));

//   ,     
// America/Los_Angeles   

//      --
console.log(new Intl.DateTimeFormat("en-US").format(date));
// "12/19/2012"

//      --
console.log(new Intl.DateTimeFormat("en-GB").format(date));
// "20/12/2012"

//     --
console.log(new Intl.DateTimeFormat("ko-KR").format(date));
// "2012. 12. 20."

//        
console.log(new Intl.DateTimeFormat("ar-EG").format(date));
// "//"

//        ,
//   2012   24-   
console.log(new Intl.DateTimeFormat("ja-JP-u-ca-japanese").format(date));
// "24/12/20"

//      , 
// ,    ,    
console.log(new Intl.DateTimeFormat(["ban", "id"]).format(date));
// "20/12/2012"

options

options:

js
const date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0, 200));

//        
let options = {
  weekday: "long",
  year: "numeric",
  month: "long",
  day: "numeric",
};
console.log(new Intl.DateTimeFormat("de-DE", options).format(date));
// "Donnerstag, 20. Dezember 2012"

//     UTC   
options.timeZone = "UTC";
options.timeZoneName = "short";
console.log(new Intl.DateTimeFormat("en-US", options).format(date));
// "Thursday, December 20, 2012, GMT"

//    
options = {
  hour: "numeric",
  minute: "numeric",
  second: "numeric",
  timeZone: "Australia/Sydney",
  timeZoneName: "short",
};
console.log(new Intl.DateTimeFormat("en-AU", options).format(date));
// "2:00:00 pm AEDT"

//     
options.fractionalSecondDigits = 3; //      
console.log(new Intl.DateTimeFormat("en-AU", options).format(date));
// "2:00:00.200 pm AEDT"

//      24-  
options = {
  year: "numeric",
  month: "numeric",
  day: "numeric",
  hour: "numeric",
  minute: "numeric",
  second: "numeric",
  hour12: false,
  timeZone: "America/Los_Angeles",
};
console.log(new Intl.DateTimeFormat("en-US", options).format(date));
// "12/19/2012, 19:00:00"

//   ,     ,   undefined
console.log(new Intl.DateTimeFormat(undefined, options).format(date));
// "12/19/2012, 19:00:00"

//     
options = { hour: "numeric", dayPeriod: "short" };
console.log(new Intl.DateTimeFormat("en-US", options).format(date));
// 10 at night

options:

js
const options = { calendar: "chinese", numberingSystem: "arab" };
const dateFormat = new Intl.DateTimeFormat(undefined, options);
const usedOptions = dateFormat.resolvedOptions();

console.log(usedOptions.calendar);
// "chinese"

console.log(usedOptions.numberingSystem);
// "arab"

console.log(usedOptions.timeZone);
// "America/New_York" (the users default timezone)

Specification
ECMAScript 2027 Internationalization API Specification
# datetimeformat-objects


   
      
        
      
    
          

Web Proxy Viewer  |  New URL  |  Original Page