admin管理员组文章数量:1335419
I use the 3 browsers to output this result.
Chrome:
new Date().toLocaleString()
> "Sun Sep 04 2011 21:40:04 GMT+0800 (HKT)"
Safari:
new Date().toLocaleString()
> "2011年9月4日 下午09时54分51秒格林尼治标准时间+0800"
FF:
new Date().toLocaleString()
> "Sun Sep 4 21:46:03 2011"
why not the same output result? timezoom?
I use the 3 browsers to output this result.
Chrome:
new Date().toLocaleString()
> "Sun Sep 04 2011 21:40:04 GMT+0800 (HKT)"
Safari:
new Date().toLocaleString()
> "2011年9月4日 下午09时54分51秒格林尼治标准时间+0800"
FF:
new Date().toLocaleString()
> "Sun Sep 4 21:46:03 2011"
why not the same output result? timezoom?
Share Improve this question edited Sep 4, 2011 at 14:20 Uwe Keim 40.8k61 gold badges189 silver badges304 bronze badges asked Sep 4, 2011 at 14:04 Thinking80sThinking80s 2,8703 gold badges17 silver badges16 bronze badges 4- What is the output in each browser? – Matt Ball Commented Sep 4, 2011 at 14:06
- chrome: new Date().toLocaleString() "Sun Sep 04 2011 21:40:04 GMT+0800 (HKT)" safari: >>> new Date().toLocaleString() "2011年9月4日 下午09时54分51秒格林尼治标准时间+0800" FF: >>> new Date().toLocaleString() "Sun Sep 4 21:46:03 2011" – Thinking80s Commented Sep 4, 2011 at 14:10
- I hesitated calling this a duplicate of stackoverflow./questions/2115725/… but this is the real question, the other one is only a good question by luck! – Stefano Commented Nov 16, 2011 at 15:46
-
Try to use localization parameter. Example:
new Date().toLocaleString("en-us")
– Bohdan Kuts Commented Jul 22, 2015 at 13:05
3 Answers
Reset to default 2It depends on the configuration of the puter, the user's preferred date format, obviously the user's locale, and how the browser determines this.
You should really prefer using a proper date library such as datejs for formatting.
See their Date.toString()
and format specifiers
.
That's a bug in webkit, actually; in particular in Chrome but Safari is indeed affected too: http://code.google./p/chromium/issues/detail?id=3607
toLocaleString() does not translate to the locale!
The worst is, it's closed as WontFix. How is that possible? We should try and re-open it. The conclusion on the bug is that somewhen a new javascript globalization apis (that is well explained here) will appear. That doesn't sound like a solution to me!
In any case, if possible, follow @arnaud576875 suggestion to use datejs which is old but still very good.
Check this link
And this example:
var event = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
// British English uses day-month-year order and 24-hour time without AM/PM
console.log(event.toLocaleString('en-GB', { timeZone: 'UTC' }));
// expected output: 20/12/2012, 03:00:00
// Korean uses year-month-day order and 12-hour time with AM/PM
console.log(event.toLocaleString('ko-KR', { timeZone: 'UTC' }));
// expected output: 2012. 12. 20. 오전 3:00:00
本文标签: javascriptjs Date toLocaleStringStack Overflow
版权声明:本文标题:javascript - js Date toLocaleString - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742387838a2465391.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论