new Date('2016-10-31') returning Sun Oct 30 2016

元气小坏坏 提交于 2020-01-03 17:10:27

问题


I'm in the Azores islands and yesterday (30 October 2016) the timezone has changed from GMT+0000 (AZOST) to GMT-0100 (AZOT).

Now new Date('2016-10-31') is returning Sun Oct 30 2016 23:00:00 GMT-0100 (AZOT):

Is this the correct behaviour from the JavaScript Date object? I was expecting the output to be Mon Oct 31 2016...


回答1:


From this documentation (emphasis mine):

Note: parsing of date strings with the Date constructor (and Date.parse, they are equivalent) is strongly discouraged due to browser differences and inconsistencies. Support for RFC 2822 format strings is by convention only. Support for ISO 8601 formats differs in that date-only strings (e.g. "1970-01-01") are treated as UTC, not local.



来源:https://stackoverflow.com/questions/40342395/new-date2016-10-31-returning-sun-oct-30-2016

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!