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:

c# httpclient The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

 If we get this error while trying to get http reponse using HttpClient object, it could mean that certificate validation fails for the remo...