JavaScript toLocaleString() Method returns a Date object as a string, using locale settings. The default language depends on the locale setup on your computer browser.
toLocaleString()
toLocaleString(locales)
toLocaleString(locales, options)
JavaScript toLocaleString
Simple example code.
<!DOCTYPE html>
<html>
<body>
<script>
const event = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
// British English uses d-m-y order and 24-hour time without AM/PM
console.log(event.toLocaleString('en-GB', { timeZone: 'UTC' }));
// Korean uses y-m-d order and 12-hour time with AM/PM
console.log(event.toLocaleString('ko-KR', { timeZone: 'UTC' }));
</script>
</body>
</html>
Output:
Parameter Values – locales
ar-SA
Arabic (Saudi Arabia)bn-BD
Bangla (Bangladesh)bn-IN
Bangla (India)cs-CZ
Czech (Czech Republic)da-DK
Danish (Denmark)de-AT
Austrian Germande-CH
“Swiss” Germande-DE
Standard German (as spoken in Germany)el-GR
Modern Greeken-AU
Australian Englishen-CA
Canadian Englishen-GB
British Englishen-IE
Irish Englishen-IN
Indian Englishen-NZ
New Zealand Englishen-US
US Englishen-ZA
English (South Africa)es-AR
Argentine Spanishes-CL
Chilean Spanishes-CO
Colombian Spanishes-ES
Castilian Spanish (as spoken in Central-Northern Spain)es-MX
Mexican Spanishes-US
American Spanishfi-FI
Finnish (Finland)fr-BE
Belgian Frenchfr-CA
Canadian Frenchfr-CH
“Swiss” Frenchfr-FR
Standard French (especially in France)he-IL
Hebrew (Israel)hi-IN
Hindi (India)hu-HU
Hungarian (Hungary)id-ID
Indonesian (Indonesia)it-CH
“Swiss” Italianit-IT
Standard Italian (as spoken in Italy)ja-JP
Japanese (Japan)ko-KR
Korean (Republic of Korea)nl-BE
Belgian Dutchnl-NL
Standard Dutch (as spoken in The Netherlands)no-NO
Norwegian (Norway)pl-PL
Polish (Poland)pt-BR
Brazilian Portuguesept-PT
European Portuguese (as written and spoken in Portugal)ro-RO
Romanian (Romania)ru-RU
Russian (Russian Federation)sk-SK
Slovak (Slovakia)sv-SE
Swedish (Sweden)ta-IN
Indian Tamilta-LK
Sri Lankan Tamilth-TH
Thai (Thailand)tr-TR
Turkish (Turkey)zh-CN
Mainland China, simplified characterszh-HK
Hong Kong, traditional characterszh-TW
Taiwan, traditional characters
Option (Optional):- An object were you can set some properties. Legal properties:
dateStyle | Legal values:"full" "long" "medium" "short" |
timeStyle | "full" "long" "medium" "short" |
localeMatcher | "best-fit" (default)"lookup" |
timeZone | |
hour12 | false true |
hourCycle | "h11" "h12" "h23" "h24" |
formatMatcher | "basic" (default) |
weekday | "long" "short" "narrow “ |
year | "2-digit" "numeric" |
month | "2-digit" "long" "narrow" "numeric" "short" |
day | "2-digit" "numeric" |
hour | "2-digit" "numeric" |
minute | "2-digit" "numeric" |
second | "2-digit" "numeric" |
timeZoneName | "long" "short" |
Do comment if you have any doubts or suggestions on this JS method.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version