Date.toLocaleDateString()如何工作? [英] How does Date.toLocaleDateString() work?

查看:500
本文介绍了Date.toLocaleDateString()如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须用本地用户的配置来表示日期。遵循 MDN 描述:


toLocaleDateString方法依赖于格式化日期中底层操作的
系统。它使用操作系统的
格式化约定将日期转换为字符串,其中脚本是
运行。例如,在美国,月份出现在日期(04/15/98)之前的
,而在德国,日期出现在
月份(15.04.98)之前。


我这样做:

  var date = new Date(); 
console.log(date.toLocaleDateString());

它输出 2012年10月13日星期六但我期望的是 Sabato,13 Ottobre,2012 (这是意大利日期格式)。
现在,我的浏览器和我的系统的配置设置正确(意大利语和上面的格式日期),所以我不明白 toLocaleDateString 如何工作。 / p>

我可以正确吗?

解决方案



这些是我的测试:

 

code>(new Date())。toLocaleDateString() - > 4/9/2013​​(意大利语格式为'd / m / Y')和Chrome 29
(新日期())。toLocaleDateString() - > firecoledì4 settembre 2013​​(意大利语格式为D d M Y)with Firefox 22

使用最新的浏览器版本。


I've to represent the date with local user's configurations. Follows the MDN description:

The toLocaleDateString method relies on the underlying operating system in formatting dates. It converts the date to a string using the formatting convention of the operating system where the script is running. For example, in the United States, the month appears before the date (04/15/98), whereas in Germany the date appears before the month (15.04.98).

I do this:

var date = new Date ();
console.log (date.toLocaleDateString ());

It prints out Saturday, October 13, 2012 but what I expect is Sabato, 13 Ottobre, 2012 (that's the Italian date format). Now, configurations of my browser and my system are set properly (Italian language and the above format date) so I don't understand how does toLocaleDateString work.

Am I doing it right?

解决方案

This question is out-of-date.

These are my tests:

(new Date ()).toLocaleDateString () -> "4/9/2013" (italian format 'd/m/Y') with Chrome 29
(new Date ()).toLocaleDateString () -> "mercoledì 4 settembre 2013" (italian format 'D d M Y') with Firefox 22

It works with newest browsers versions.

这篇关于Date.toLocaleDateString()如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆