Chrome, javascript Date and toLocaleString()
Why doesn't Chrome specify AM or PM when displaying a date by using date.toLocaleString()
? The string I get is Fri Jun 25 2010 11:开发者_如何学Python21:09 GMT+1000
. While IE returns almost the same string but with AM
after the time.
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?
Update. Found this bug 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.
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. – ECMAScript 5, § 15.9.5.5
Instead, you can more or less test the user's language setting and build a string yourself.
精彩评论