目录

JavaScript Date toLocaleString()

示例

使用区域设置约定获取字符串形式的日期:

const d = new Date();
let text = d.toLocaleString();
亲自试一试 »

描述

toLocaleString() 方法使用区域设置以字符串形式返回 Date 对象。

默认语言取决于您计算机上的区域设置。


浏览器支持

toLocaleString()是 ECMAScript1 (ES1) 功能。

所有浏览器均完全支持 ES1 (JavaScript 1997):

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes

语法

Date.toLocaleString( locales, options)

参数值

Parameter Description
locales

尝试一下
Optional. Which language specific format to use.
Click on the "Try it" button to see all values in action.
Legal Values:

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 German
de-CH "Swiss" German
de-DE Standard German (as spoken in Germany)
el-GR Modern Greek
en-AU Australian English
en-CA Canadian English
en-GB British English
en-IE Irish English
en-IN Indian English
en-NZ New Zealand English
en-US US English
en-ZA English (South Africa)
es-AR Argentine Spanish
es-CL Chilean Spanish
es-CO Colombian Spanish
es-ES Castilian Spanish (as spoken in Central-Northern Spain)
es-MX Mexican Spanish
es-US American Spanish
fa-IR Iranian (Iran)
fi-FI Finnish (Finland)
fr-BE Belgian French
fr-CA Canadian French
fr-CH "Swiss" French
fr-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" Italian
it-IT Standard Italian (as spoken in Italy)
ja-JP Japanese (Japan)
ko-KR Korean (Republic of Korea)
nl-BE Belgian Dutch
nl-NL Standard Dutch (as spoken in The Netherlands)
no-NO Norwegian (Norway)
pl-PL Polish (Poland)
pt-BR Brazilian Portuguese
pt-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 Tamil
ta-LK Sri Lankan Tamil
th-TH Thai (Thailand)
tr-TR Turkish (Turkey)
zh-CN Mainland China, simplified characters
zh-HK Hong Kong, traditional characters
zh-TW Taiwan, traditional characters
options Optional. An object where 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"
"best-fit"
(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"

浏览器对区域设置和选项的支持

Chrome IE / Edge Firefox Safari Opera
24 11 29 10 15

技术细节

返回值: 一个字符串,将日期和时间表示为字符串
JavaScript 版本: ECMA脚本1