我覺得我在這裏錯過了一些東西。Date.getDay()返回不同的值
Date.getDay()方法應該從0-6返回一個值。星期日爲0,星期六爲6。
現在我有兩個日期,兩者都是「星期天」,這應該返回0。
new Date('1990-11-11').getDay() // returns 6
new Date('2016-1-3').getDay() // returns 0
是什麼原因造成的差異?我敢於質疑.getDay()
方法的有效性,但我無法弄清楚發生了什麼。
編輯
> new Date('1990-11-11')
Sat Nov 10 1990 17:00:00 GMT-0700 (MST)
> new Date('2016-01-03')
Sat Jan 02 2016 17:00:00 GMT-0700 (MST)
> new Date('2016-1-3') // they say this format is wrong, but it returns the right date
Sun Jan 03 2016 00:00:00 GMT-0700 (MST)
我不明白是怎麼回事。 1990年1月3日星期日和11月11日是星期天。爲什麼說星期六?
在我的機器都返回0。 – ppasler
在我的機器也返回0 新的日期(「1990年11月11日」)。getDay()返回新的日期(「2016年1月3日」 ).getDay() return 0 – CommonPlane
在我的情況下都返回0。檢查這個https://jsfiddle.net/yzyqruyc/ – amulya349