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. Itโ€™s been available across browsers since โจ2017๋…„ 9์›”โฉ.

Intl.DateTimeFormat ์€ ์–ธ์–ด์— ๋งž๋Š” ๋‚ ์งœ ๋ฐ ์‹œ๊ฐ„ ์„œ์‹์„ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•œ ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค.

์‹œ๋„ํ•ด ๋ณด๊ธฐ

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.format()

DateTimeFormat ๊ฐ์ฒด์˜ ๋กœ์ผ€์ผ๊ณผ ์„œ์‹ ์˜ต์…˜์— ๋งž์ถฐ ๋‚ ์งœ๋ฅผ ์„œ์‹ํ™”ํ•ด ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

Intl.DateTimeFormat.prototype.formatToParts()

๋‚ ์งœ ์„œ์‹ ๋ฌธ์ž์—ด์˜ ๊ฐ ๋ถ€๋ถ„์„ ๋ถ„ํ•ดํ•˜์—ฌ ํ† ํฐ ๊ฐ์ฒด๋กœ ๋งŒ๋“ค๊ณ  Array๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๋กœ์ผ€์ผ์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž ์ง€์ • ์„œ์‹์„ ์ ์šฉํ•  ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Intl.DateTimeFormat.prototype.resolvedOptions()

DateTimeFormat ๊ฐ์ฒด๋ฅผ ์ดˆ๊ธฐํ™”ํ•  ๋•Œ ํ• ๋‹น๋œ ๋กœ์ผ€์ผ ๋ฐ ์„œ์‹ ์˜ต์…˜์˜ ๊ณ„์‚ฐ ๊ฐ’์„ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

Intl.DateTimeFormat.prototype.formatRange()

๋‘ ๊ฐœ์˜ Dates๋ฅผ ๋ฐ›์€ ํ›„, ํ˜„์žฌ ํ• ๋‹น๋œ ๋กœ์ผ€์ผ๊ณผ ์˜ต์…˜ ๋‚ด์—์„œ ๊ฐ€์žฅ ๊ฐ„๊ฒฐํ•œ ํ˜•ํƒœ๋กœ ๋‘ ๋‚ ์งœ์˜ ๋ฒ”์œ„๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

Intl.DateTimeFormat.prototype.formatRangeToParts()

๋‘ ๊ฐœ์˜ Dates๋ฅผ ๋ฐ›์€ ํ›„, ํ˜„์žฌ ํ• ๋‹น๋œ ๋กœ์ผ€์ผ๊ณผ ์˜ต์…˜ ๋‚ด์—์„œ ๊ฐ€์žฅ ๊ฐ„๊ฒฐํ•œ ํ˜•ํƒœ๋กœ ๋‘ ๋‚ ์งœ์˜ ๋ฒ”์œ„๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฌธ์ž์—ด์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด์˜ ๊ฐ ๋ถ€๋ถ„์„ ๋ถ„ํ•ดํ•˜์—ฌ ํ† ํฐ ๊ฐ์ฒด๋กœ ๋งŒ๋“ค๊ณ  Array๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์ œ

DateTimeFormat ์‚ฌ์šฉํ•˜๊ธฐ

๋กœ์ผ€์ผ์„ ์ง€์ •ํ•˜์ง€ ์•Š๊ณ  ์‚ฌ์šฉํ•˜๋ฉด ๊ธฐ๋ณธ ๋กœ์ผ€์ผ๊ณผ ๊ธฐ๋ณธ ์˜ต์…˜์˜ ์„œ์‹์„ ์ ์šฉํ•œ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

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

// ๋งค๊ฐœ๋ณ€์ˆ˜ ์—†์ด toLocaleString()์„ ํ˜ธ์ถœํ•œ ๊ฒฐ๊ณผ๋Š”
// ๊ตฌํ˜„์ฒด, ๊ธฐ๋ณธ ๋กœ์ผ€์ผ, ๊ธฐ๋ณธ ์‹œ๊ฐ„๋Œ€์— ๋‹ค๋ผ ๋‹ฌ๋ผ์ง
console.log(new Intl.DateTimeFormat().format(date));
// โ†’ ko-KR ๋กœ์ผ€์ผ(์–ธ์–ด)๊ณผ Asia/Seoul ์‹œ๊ฐ„๋Œ€(UTC+0900)์—์„œ "2012. 12. 20."

๋กœ์ผ€์ผ ์ง€์ •ํ•˜๊ธฐ

๋‹ค์Œ ์˜ˆ์ œ๋Š” ์ง€์—ญํ™”๋œ ์ˆซ์ž ์„œ์‹ ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž์˜ ์–ธ์–ด์— ์ ํ•ฉํ•œ ์„œ์‹์„ ์ ์šฉํ•˜๋ ค๋ฉด locales ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ํ•ด๋‹น ์–ธ์–ด(ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋Œ€์ฒด ์–ธ์–ด๊นŒ์ง€)๋ฅผ ์ œ๊ณตํ•˜๋Š” ๊ฑธ ์žŠ์ง€ ๋งˆ์„ธ์š”.

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

// ์•„๋ž˜ ๊ฒฐ๊ณผ๋Š” ๋ชจ๋‘ Asia/Seoul ์‹œ๊ฐ„๋Œ€๋ฅผ ์‚ฌ์šฉํ•œ ๊ฒฐ๊ณผ (UTC+0900, ํ•œ๊ตญ ํ‘œ์ค€์‹œ)

// ํ•œ๊ตญ์–ด์—์„œ ๋‚ ์งœ ํ‘œ๊ธฐ๋Š” ์—ฐ์›”์ผ ์ˆœ์„œ
console.log(new Intl.DateTimeFormat("ko-KR").format(date));
// โ†’ "2012. 12. 20."

// ๋ฏธ๊ตญ ์˜์–ด์—์„œ ๋‚ ์งœ ํ‘œ๊ธฐ๋Š” ์›”์ผ๋…„ ์ˆœ์„œ
console.log(new Intl.DateTimeFormat("en-US").format(date));
// โ†’ "12/20/2012"

// ์˜๊ตญ ์˜์–ด์—์„œ ๋‚ ์งœ ํ‘œ๊ธฐ๋Š” ์ผ์›”๋…„ ์ˆœ์„œ
console.log(new Intl.DateTimeFormat("en-GB").format(date));
// โ†’ "20/12/2012"

// ๋Œ€๋ถ€๋ถ„์˜ ์•„๋ž์–ด ๊ตญ๊ฐ€์—์„œ๋Š” ์ง„์งœ ์•„๋ผ๋น„์•„ ์ˆซ์ž ์‚ฌ์šฉ
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 ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ง€์ •ํ•˜๋ฉด ๋‚ ์งœ์™€ ์‹œ๊ฐ„ ์„œ์‹ ๊ฒฐ๊ณผ๋ฅผ ์›ํ•˜๋Š” ํ˜•ํƒœ๋กœ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

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

// ๊ธด ๋‚ ์งœ ์„œ์‹์— ๋”ํ•ด ์š”์ผ ์š”์ฒญ
var options = {
  weekday: "long",
  year: "numeric",
  month: "long",
  day: "numeric",
};
console.log(new Intl.DateTimeFormat("de-DE", options).format(date));
// โ†’ "Donnerstag, 20. Dezember 2012"

// ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์ด GMT๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๊ณ , ๊ทธ ์ ์„ ๋ช…์‹œํ•ด์•ผ ํ•  ๋•Œ
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"

// ๋ฏธ๊ตญ์—์„œ๋„ 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"

// ์˜ต์…˜์„ ์ง€์ •ํ•˜๋ฉด์„œ ๋กœ์ผ€์ผ์€ ๋ธŒ๋ผ์šฐ์ € ๊ธฐ๋ณธ๊ฐ’์„ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์„ ๋• 'default' ์ง€์ •
console.log(new Intl.DateTimeFormat("default", options).format(date));
// โ†’ "2012. 12. 19. 19์‹œ 0๋ถ„ 0์ดˆ"

// ์˜ค์ „/์˜คํ›„ ์‹œ๊ฐ„ ํ‘œ์‹œ๊ฐ€ ํ•„์š”ํ•  ๋•Œ
options = { hour: "numeric", dayPeriod: "short" };
console.log(new Intl.DateTimeFormat("en-US", options).format(date));
// โ†’ 10 at night

๋ช…์„ธ

Specification
ECMAScriptยฎ 2026 Internationalization API Specification
# datetimeformat-objects

๋ธŒ๋ผ์šฐ์ € ํ˜ธํ™˜์„ฑ

๊ฐ™์ด ๋ณด๊ธฐ