Thursday, March 17, 2016

Javascript Date format gotchas

I was debugging some date time format issue in chrome when I found out that in console

new Date('2016-04-16T15:15:00') returns Sat Apr 16 2016 16:15:00 GMT+0100 (GMT Daylight Time)

while

new Date('2016-04-16 15:15:00') returns Sat Apr 16 2016 15:15:00 GMT+0100 (GMT Daylight Time)


This is because JavaScript dates are parsed in the local time of the browser, unless you use the ISO date format "2015-03-22", which will be parsed as UTC.

Also, moment.js is probably the easiest and cleanest solution for all such issues.

More Info here: http://stackoverflow.com/questions/28989484/eliminating-javascript-daylight-saving-time-gap-a-cross-browser-solution

No comments:

SSL Error - The connection for this site is not secure

 After cloning a git repo of dot net framework website and trying to run it all I could see was this error Turns out the fix was to simply e...