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"
로케일을 지정하지 않고 사용하면 기본 로케일과 기본 옵션의 서식을 적용한 문자열을 반환합니다.
js
var date =newDate(Date.UTC(2012,11,20,3,0,0));// 매개변수 없이 toLocaleString()을 호출한 결과는// 구현체, 기본 로케일, 기본 시간대에 다라 달라짐
console.log(newIntl.DateTimeFormat().format(date));// → ko-KR 로케일(언어)과 Asia/Seoul 시간대(UTC+0900)에서 "2012. 12. 20."
다음 예제는 지역화된 숫자 서식 방법을 보여줍니다. 사용자의 언어에 적합한 서식을 적용하려면 locales 매개변수로 해당 언어(필요한 경우 대체 언어까지)를 제공하는 걸 잊지 마세요.
js
var date =newDate(Date.UTC(2012,11,20,3,0,0));// 아래 결과는 모두 Asia/Seoul 시간대를 사용한 결과 (UTC+0900, 한국 표준시)// 한국어에서 날짜 표기는 연월일 순서
console.log(newIntl.DateTimeFormat("ko-KR").format(date));// → "2012. 12. 20."// 미국 영어에서 날짜 표기는 월일년 순서
console.log(newIntl.DateTimeFormat("en-US").format(date));// → "12/20/2012"// 영국 영어에서 날짜 표기는 일월년 순서
console.log(newIntl.DateTimeFormat("en-GB").format(date));// → "20/12/2012"// 대부분의 아랍어 국가에서는 진짜 아라비아 숫자 사용
console.log(newIntl.DateTimeFormat("ar-EG").format(date));// → "٢٠/١٢/٢٠١٢"// 일본어의 경우 어플리케이션에 연호를 사용해야 할 수도 있음// 2012년은 헤이세이 24년
console.log(newIntl.DateTimeFormat("ja-JP-u-ca-japanese").format(date));// → "24/12/20"// 발리어와 같이 지원되지 않을 수도 있는 언어를 지정할 때는// 다음과 같이 대체 언어를 지정할 수 있음. 아래의 경우 대체 언어는 인도어
console.log(newIntl.DateTimeFormat(["ban","id"]).format(date));// → "20/12/2012"
options 매개변수를 지정하면 날짜와 시간 서식 결과를 원하는 형태로 바꿀 수 있습니다.
js
var date =newDate(Date.UTC(2012,11,20,3,0,0));// 긴 날짜 서식에 더해 요일 요청var options ={weekday:"long",year:"numeric",month:"long",day:"numeric",};
console.log(newIntl.DateTimeFormat("de-DE", options).format(date));// → "Donnerstag, 20. Dezember 2012"// 어플리케이션이 GMT를 사용해야 하고, 그 점을 명시해야 할 때
options.timeZone ="UTC";
options.timeZoneName ="short";
console.log(newIntl.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(newIntl.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(newIntl.DateTimeFormat("en-US", options).format(date));// → "12/19/2012, 19:00:00"// 옵션을 지정하면서 로케일은 브라우저 기본값을 사용하고 싶을 땐 'default' 지정
console.log(newIntl.DateTimeFormat("default", options).format(date));// → "2012. 12. 19. 19시 0분 0초"// 오전/오후 시간 표시가 필요할 때
options ={hour:"numeric",dayPeriod:"short"};
console.log(newIntl.DateTimeFormat("en-US", options).format(date));// → 10 at night
Tip: you can click/tap on a cell for more information.
Full support
Full support
Partial support
Partial support
No support
No support
See implementation notes.
Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.