File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -480,7 +480,7 @@ d.setDate(9) // 1357660800000
480
480
d // Wed Jan 09 2013 00:00:00 GMT+0800 (CST)
481
481
```
482
482
483
- ` set* ` 方法的参数都会自动折算。以` setDate ` 为例,如果参数超过当月的最大天数,则向下一个月顺延,如果参数是负数,表示从上个月的最后一天开始减去的天数。
483
+ ` set* ` 方法的参数都会自动折算。以` setDate() ` 为例,如果参数超过当月的最大天数,则向下一个月顺延,如果参数是负数,表示从上个月的最后一天开始减去的天数。
484
484
485
485
``` javascript
486
486
var d1 = new Date (' January 6, 2013' );
@@ -490,10 +490,12 @@ d1 // Fri Feb 01 2013 00:00:00 GMT+0800 (CST)
490
490
491
491
var d2 = new Date (' January 6, 2013' );
492
492
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)
495
495
```
496
496
497
+ 上面代码中,` d1.setDate(32) ` 将日期设为1月份的32号,因为1月份只有31号,所以自动折算为2月1日。` d2.setDate(-1) ` 表示设为上个月的倒数第二天,即12月30日。
498
+
497
499
` set ` 类方法和` get ` 类方法,可以结合使用,得到相对时间。
498
500
499
501
``` javascript
You can’t perform that action at this time.
0 commit comments