File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -480,7 +480,7 @@ d.setDate(9) // 1357660800000
480480d // Wed Jan 09 2013 00:00:00 GMT+0800 (CST)
481481```
482482
483- ` set* ` 方法的参数都会自动折算。以` setDate ` 为例,如果参数超过当月的最大天数,则向下一个月顺延,如果参数是负数,表示从上个月的最后一天开始减去的天数。
483+ ` set* ` 方法的参数都会自动折算。以` setDate() ` 为例,如果参数超过当月的最大天数,则向下一个月顺延,如果参数是负数,表示从上个月的最后一天开始减去的天数。
484484
485485``` javascript
486486var d1 = new Date (' January 6, 2013' );
@@ -490,10 +490,12 @@ d1 // Fri Feb 01 2013 00:00:00 GMT+0800 (CST)
490490
491491var d2 = new Date (' January 6, 2013' );
492492
493- d .setDate (- 1 ) // 1356796800000
494- d // Sun Dec 30 2012 00:00:00 GMT+0800 (CST)
493+ d2 .setDate (- 1 ) // 1356796800000
494+ d2 // Sun Dec 30 2012 00:00:00 GMT+0800 (CST)
495495```
496496
497+ 上面代码中,` d1.setDate(32) ` 将日期设为1月份的32号,因为1月份只有31号,所以自动折算为2月1日。` d2.setDate(-1) ` 表示设为上个月的倒数第二天,即12月30日。
498+
497499` set ` 类方法和` get ` 类方法,可以结合使用,得到相对时间。
498500
499501``` javascript
You can’t perform that action at this time.
0 commit comments