Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 19d0628

Browse files
committed
docs(stdlib): fix Date.setDate
1 parent 786148c commit 19d0628

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎docs/stdlib/date.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ d.setDate(9) // 1357660800000
480480
d // Wed Jan 09 2013 00:00:00 GMT+0800 (CST)
481481
```
482482

483-
`set*`方法的参数都会自动折算。以`setDate`为例,如果参数超过当月的最大天数,则向下一个月顺延,如果参数是负数,表示从上个月的最后一天开始减去的天数。
483+
`set*`方法的参数都会自动折算。以`setDate()`为例,如果参数超过当月的最大天数,则向下一个月顺延,如果参数是负数,表示从上个月的最后一天开始减去的天数。
484484

485485
```javascript
486486
var d1 = new Date('January 6, 2013');
@@ -490,10 +490,12 @@ d1 // Fri Feb 01 2013 00:00:00 GMT+0800 (CST)
490490

491491
var 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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /