js在当前日期添加天、周、月、年数

js在当前日期添加天、周、月、年数


//创建date
var nowDate = new Date();

//添加天数
nowDate .setDate(nowDate .getDate() + 1);

//添加周		添加周没有特定的获取周的方法,所以用添加天的方式,来添加七天,即为一周
nowDate .setDate(nowDate .getDate() + 7);

//添加月数
nowDate .setMonth(nowDate .getMonth() + 1);

//添加年数
nowDate .setYear(nowDate .getYear() + 1);

猜你喜欢

转载自blog.csdn.net/qq_45844443/article/details/118703463