I have a system that returns a JSON object that contains dates in string format.
These dates are in the format “2012-10-19 06:05:38 GMT” (no… I’m stuck with them like this)
So I need to get this into a date object (d) ready to output as d.toLocaleDateString()
In chrome it works perfectly by just passing the string to a new Date (Bad bad Chrome – makes Eric lazy), but of course it fails in FF and IE
I can fix it by splitting the string but its not pretty and I’ve not figured out dealing with the offsets from GMT.
There must be a more elegant way…?
I’m sure someone here can do it in one line.
It’s not quite a one-liner, but if you know all your dates will be GMT, something like the following should work: