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
์ฌ์ฉํ๊ธฐ
๋ก์ผ์ผ์ ์ง์ ํ์ง ์๊ณ ์ฌ์ฉํ๋ฉด ๊ธฐ๋ณธ ๋ก์ผ์ผ๊ณผ ๊ธฐ๋ณธ ์ต์ ์ ์์์ ์ ์ฉํ ๋ฌธ์์ด์ ๋ฐํํฉ๋๋ค.
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
๋งค๊ฐ๋ณ์๋ก ํด๋น ์ธ์ด(ํ์ํ ๊ฒฝ์ฐ ๋์ฒด ์ธ์ด๊น์ง)๋ฅผ ์ ๊ณตํ๋ ๊ฑธ ์์ง ๋ง์ธ์.
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
๋งค๊ฐ๋ณ์๋ฅผ ์ง์ ํ๋ฉด ๋ ์ง์ ์๊ฐ ์์ ๊ฒฐ๊ณผ๋ฅผ ์ํ๋ ํํ๋ก ๋ฐ๊ฟ ์ ์์ต๋๋ค.
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 |
๋ธ๋ผ์ฐ์ ํธํ์ฑ
Loadingโฆ