我有一个日期对象:
var thedate = new Date("2012-05-02T11:00:00.000+0000");
什么时候getMonth()我得到4,但什么时候getDay()我得到3?我想这样做,以便当我调用 时getDay,我得到原始字符串 (2) 中反映的内容。我可以从 中减去 1 getDay(),但我不确定这是否是正确的方法,以及它是否适用于所有日期。
我有一个日期对象:
var thedate = new Date("2012-05-02T11:00:00.000+0000");
什么时候getMonth()我得到4,但什么时候getDay()我得到3?我想这样做,以便当我调用 时getDay,我得到原始字符串 (2) 中反映的内容。我可以从 中减去 1 getDay(),但我不确定这是否是正确的方法,以及它是否适用于所有日期。
According to MDN, getMonth will return a number in the range 0-11 (so 0 is for January), and getDay will return the day of the week in the range 0-6 (so 0 is for Sunday). If you want to get the day in month, you should use getDate, which will return a number in the range 1-31.
getDay/getMonth将返回当天的索引,从 0 开始,因此 +1。
getDay() 返回星期几(从 0 到 6)
在这里阅读:http: //www.w3schools.com/jsref/jsref_obj_date.asp