• 获取当前日期以及三天后的日期


    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);//打印输出就是三天后的日期啦~
     
  • 相关阅读:
    自主问题--KMP算法
    题解--luogu--CSP2019.S.Day2.T4--Emiya 家今天的饭
    浅谈——RMQ
    浅谈——LCA
    NOIP(si le)或者CSP初赛之——前序中序后序,前缀中缀后缀
    浅说——查分约束
    浅说——tarjan
    C++ RQNOJ 星门龙跃
    C++ 洛谷 1261:【例9.5】城市交通路网
    刷题
  • 原文地址:https://www.cnblogs.com/bjdx1314/p/11429757.html
Copyright © 2020-2023  润新知