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
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
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:
Post a Comment