时间相加减

var  date= new  Date(); //当前时间对象,2017-10-31
date.setDate(date.getDate()+1); //在原有的天数上加一天
date.getDate(); //获取天数
date.getMonth(); //获取月数,注意月是从0~11,如显示就要加1,date.getMonth()+1
date.setMonth(date.getMonth()+1); //加一月,如果是减一个月,就传入负数
date.getFullYear(); //获取年份
date.setYear(date.getFullYear()+1); //在当前年份上加1年,如果是减就传入负数
 

猜你喜欢

转载自www.cnblogs.com/MR-cui/p/9115631.html