[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString [Back]  [Original]

Date.prototype.toLocaleString() - 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

Date.prototype.toLocaleString()

Baseline Widely available

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

toLocaleString() . Intl.DateTimeFormat API Intl.DateTimeFormat .

In this article

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

// British English uses day-month-year order and 24-hour time without AM/PM
console.log(event.toLocaleString("en-GB", { timeZone: "UTC" }));
// Expected output: "20/12/2012, 03:00:00"

// Korean uses year-month-day order and 12-hour time with AM/PM
console.log(event.toLocaleString("ko-KR", { timeZone: "UTC" }));
// Expected output: "2012. 12. 20.  3:00:00"

js
toLocaleString()
toLocaleString(locales)
toLocaleString(locales, options)

locales, options .

Intl.DateTimeFormat API , Intl.DateTimeFormat() . Intl.DateTimeFormat , .

locales Optional

BCP 47 . Intl.DateTimeFormat() locales .

Intl.DateTimeFormat , .

options Optional

. Intl.DateTimeFormat() options . weekday, year, month, day, dayPeriod, hour, minute, second, fractionalSecondDigits undefined, year, month, day, hour, minute, second "numeric" .

Intl.DateTimeFormat .

. Intl.DateTimeFormat() constructor

Intl.DateTimeFormat new Intl.DateTimeFormat(locales, options).format(date) .

toLocaleString()

, .

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

//   toLocaleString()  ,  ,    
console.log(date.toLocaleString());
//  "12/11/2012, 7:00:00 PM" en-Us   America/Los_Angeles   

locales, options . RangeError .

js
function toLocaleStringSupportsLocales() {
  try {
    new Date().toLocaleString("i");
  } catch (e) {
    return e.name === "RangeError";
  }
  return false;
}

locales

. ( ) , locales .

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

//      
// America/Los_Angeles for the US

//   --  AM/PM  12 
console.log(date.toLocaleString("en-US"));
//  "12/19/2012, 7:00:00 PM"

//   --  AM/PM  24 
console.log(date.toLocaleString("en-GB"));
//  "20/12/2012 03:00:00"

//  --  AM/PM  12 
console.log(date.toLocaleString("ko-KR"));
//  "2012. 12. 20.  12:00:00"

//        
console.log(date.toLocaleString("ar-EG"));
//  "// :: "

//  ,       
// 2012  Heisei 24 
console.log(date.toLocaleString("ja-JP-u-ca-japanese"));
//  "24/12/20 12:00:00"

//         ,   . (  )
console.log(date.toLocaleString(["ban", "id"]));
//  "20/12/2012 11.00.00"

options

toLocaleString() options .

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

// Request a weekday along with a long date
const options = {
  weekday: "long",
  year: "numeric",
  month: "long",
  day: "numeric",
};

console.log(date.toLocaleString("de-DE", options));
//  "Donnerstag, 20. Dezember 2012"

//  UTC        .
options.timeZone = "UTC";
options.timeZoneName = "short";

console.log(date.toLocaleString("en-US", options));
//  "Thursday, December 20, 2012, GMT"

// en-US 24  
console.log(date.toLocaleString("en-US", { hour12: false }));
//  "12/19/2012, 19:00:00"

, toLocaleString() . , ; .

IE Edge , .

, toLocaleString() .

js
"1/1/2019, 01:00:00" ===
  new Date("2019-01-01T01:00:00Z").toLocaleString("en-US");
// Firefox    true 
// IE Edge false 

: See also this StackOverflow thread for more details and examples.

Specification
ECMAScript 2027 LanguageSpecification
# sec-date.prototype.tolocalestring
ECMAScript 2027 Internationalization API Specification
# sup-date.prototype.tolocalestring

See also


Web Proxy Viewer  |  New URL  |  Original Page