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.
精彩评论