开发者

Javascript setFullYear

var currentDate=new Date();
currentDate.setFullY开发者_如何转开发ear(2011);
alert(currentDate);

This works, it sets the year to 2011 as expected.

alert((new Date()).setFullYear(2011));

This one doesn't work.

Any idea why? Am I misunderstanding the syntax?


When you write alert((new Date()).setFullYear(2011)), you are calling setFullYear, and passing its return value to alert.

setFullYear returns a timestamp, not the original Date object.
Therefore, it doesn't do what you want it to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜