Localised Date & Time in Javascript

I want to display a date & time string that's formatted correctly depending on the viewer's locale.
Question: can I rely on the javascript Date object's locale-specific string functions ?
Answer: yes, but only if I don't care what it looks like or how many characters are in the string.

Here's the result of my testing:


toLocaleString()
FF15:     "Tue Jul 14 14:37:05 2009"
Chrome21: "Tue Jul 14 2009 14:37:05 GMT+1200 (NZST)"
Safari6:  "14 July 2009 2:37:05 PM NZST"
IE10:  "Tuesday, 14 July 2009 2:37:05 p.m."

toLocalDateString() + ' ' + toLocaleTimeString()

FF15:     "07/14/2009 14:37:05"
Chrome21: "Tuesday, July 14, 2009 14:37:05"
Safari6: "14 July 2009 2:37:05 PM NZST"
IE10 "Tuesday, 14 July 2009 2:37:05 p.m."

Could they be any more different ?

Comments

Popular posts from this blog

Creamoata

Windows FILETIME to Javascript Date

Using an Async Iterator in Typescript