简体   繁体   English

Chrome,javascript日期和toLocaleString()

[英]Chrome, javascript Date and toLocaleString()

Why doesn't Chrome specify AM or PM when displaying a date by using date.toLocaleString() ? 当使用date.toLocaleString()显示日期时,Chrome为什么不指定AM或PM? The string I get is Fri Jun 25 2010 11:21:09 GMT+1000 . 我得到的字符串是Fri Jun 25 2010 11:21:09 GMT+1000 While IE returns almost the same string but with AM after the time. 虽然IE返回几乎相同的字符串,但在此时间之后带有AM

Is there any method on the Date object I can call to check whether it's AM or PM and, more importantly, check whether user's locale is using 12-hour cycles or 24-hours? 我可以调用Date对象上的任何方法来检查它是AM还是PM ,更重要的是,检查用户的语言环境是使用12小时制还是24小时制?

Update. 更新。 Found this bug http://code.google.com/p/v8/issues/detail?id=135 . 发现了此错误http://code.google.com/p/v8/issues/detail?id=135 It is very old, I was hoping there would be updates on it. 它很旧,我希望可以在上面进行更新。

getHours returns a value between 0 and 23 , so you can easily determine whether it's before or after noon. getHours返回023之间的值,因此您可以轻松确定它是在中午之前还是之后。

However, I don't know any method to get a kind of universal locale string. 但是,我不知道任何一种获取通用语言环境字符串的方法。 It's completely up to the browser: 这完全取决于浏览器:

The contents of the String are implementation-dependent, but are intended to represent the Date in the current time zone in a convenient, human-readable form that corresponds to the conventions of the host environment's current locale. String的内容与实现有关,但是旨在以一种方便且易于阅读的形式表示当前时区中的Date,该形式与主机环境的当前语言环境的约定相对应。 ECMAScript 5 , § 15.9.5.5 ECMAScript 5 ,第15.9.5.5节

Instead, you can more or less test the user's language setting and build a string yourself. 相反,您可以或多或少地测试用户的语言设置并自己构建一个字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM