var date=new Date();//获取当前时间
var year=date.getFullYear();//获取当前年份
var month=date.getMonth()+1;//获取当前月
var day=date.getDate();//获取当前日
var nowTime=newday+'.'+month+'.'+day;//当前日期
console.log(nowTime);打印输出就是当前日期啦~
var runYear=[31,29,31,30,31,30,31,31,30,31,30,31];//获取闰年所有月份信息
var pingYear = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];//获取平年所有月份信息
var newday=day;//定义新日期变量
var newmonth=month;//定义新日期变量
var newyear=year;//定义新日期变量
const DAYS=3;//代表3天后,如果要求四天后,值可直接设为4,依次类推
if (year % 4 == 0 && year % 100 != 0){//判断平年闰年
console.log(runYear[month-1]);
if (runYear[month - 1] - newday >= DAYS){
newday = newday + DAYS
}
else if (runYear[month-1] - newday < 2&&newmonth!=12){
newmonth=newmonth+1;
newday = DAYS-(runYear[month-1] - newday)
}
else{
newyear=newyear+1;
newmonth=1;
newday = DAYS-(runYear[month-1] - newday)
}
}
else{
if (pingYear[month - 1] - newday >= DAYS) {
console.log(month);
console.log(pingYear[month]);
newday = newday + DAYS
}
else if (pingYear[month-1] - newday < 2 && newmonth != 12) {
newmonth = newmonth + 1;
newday = DAYS-(pingYear[month-1] - newday)
}
else {
newyear = newyear + 1;
newmonth = 1;
newday = DAYS-(pingYear[month-1] - newday)
}
}
var willTime=newyear+'.'+newmonth+'.'+newday;//后三天日期
console.log(willTime);//打印输出就是三天后的日期啦~