开发者

Javascript setFullYear

开发者 https://www.devze.com 2022-12-31 11:30 出处:网络
var currentDate=new Date(); currentDate.setFullY开发者_如何转开发ear(2011); alert(currentDate);
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

精彩评论

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

关注公众号