js代码:
var lastDate = new Date(lastTime);//已得日期
var nextTime;//计算所得日期
switch (e) {
default: nextTime = lastDate
break;
case '每天': nextTime = lastDate.setDate(lastDate.getDate() + 1)
break;
case '每周': nextTime = lastDate.setDate(lastDate.getDate() + 7)
break;
case '每月': nextTime = lastDate.setMonth(lastDate.getMonth() + 1)
break;
case '每季度': nextTime = lastDate.setMonth(lastDate.getMonth() + 3)
break;
case '每半年': nextTime = lastDate.setMonth(lastDate.getMonth() + 6)
break;
case '每年': nextTime = lastDate.setFullYear(lastDate.getFullYear() + 1)
break;
case '每两年': nextTime = lastDate.setFullYear(lastDate.getFullYear() + 2)
break;
case '每三年': nextTime = lastDate.setFullYear(lastDate.getFullYear() + 3)
break;
case '每1-5年': nextTime = lastDate.setFullYear(lastDate.getFullYear() + 5)
break;
case '每5-20年': nextTime = lastDate.setFullYear(lastDate.getFullYear() + 20)
break;
}
最后得到的nextTime是一个时间戳,转成日期即可;
注意此处加年份时获取年份应使用getFullYear(),而不是getYear();
因为getYear()并不是所有浏览器都兼容。