2

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:21: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.

Egor Pavlikhin
  • 17,503
  • 16
  • 61
  • 99

1 Answers1

1

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.

Community
  • 1
  • 1
Marcel Korpel
  • 21,536
  • 6
  • 60
  • 80
  • The language setting is not a reliable indicator of preferred date format. Far better to just use an unambiguous format. ;-) – RobG May 18 '16 at 23:28