Running into a JavaScript date weirdness that I cannot wrap my head around.
I have a date/time returned via WebAPI: ‘2012-12-13T12:17:06.080’. It’s in local time (-7 UTC).
When running this date through JavaScript
var d = new Date('2012-12-14T05:32:05.543');
alert(d.toTimeString());
returns 22:32:05 MST
Then doing
var d = new Date('2012-12-14T05:32:05.543');
alert(d.toLocaleTimeString());
returns 10:32:05 PM
toTimeString/toLocaleTimeString() per JavaScript docs says it should just extract the Time portion, so why did the time change? What should I do to get it to return the correct time portion 05:32:05 without creating an supposedly unneeded function?
When you give the
Date()constructor an ISO8601 timestamp string, it always interprets it as UTC.Not all browsers behave the same way, and some don’t like those at all.