新日期('2016-10-31')返回Sun Oct Oct 2016 [英] new Date('2016-10-31') returning Sun Oct 30 2016

查看:85
本文介绍了新日期('2016-10-31')返回Sun Oct Oct 2016的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在亚速尔群岛和昨天(2016年10月30日),时区已经从GMT + 0000(AZOST)改为GMT-0100(AZOT)。



现在新日期('2016-10-31')正在返回 Sun Oct 30 2016 23:00:00 GMT-0100(AZOT)



< img src =https://i.stack.imgur.com/tPgEy.pngalt =在此输入图像说明>



这是来自JavaScript Date对象的正确行为?我期待输出是 Mon Oct 31 2016 ...

解决方案

p>从此文档(强调我的):


注意:使用Date构造函数解析日期字符串(和
Date.parse,它们是等效的)强烈地不鼓励由于
浏览器的差异和不一致。支持RFC 2822格式
字符串仅按惯例。 对于ISO 8601格式的支持在
中,日期唯一的字符串(例如1970-01-01)被视为UTC,而不是
本地。



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...

解决方案

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.

这篇关于新日期('2016-10-31')返回Sun Oct Oct 2016的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆