zoukankan      html  css  js  c++  java
  • 获取当前日期以及三天后的日期

    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);//打印输出就是三天后的日期啦~
     
  • 相关阅读:
    android_firewall or Droidwall http://code.google.com/p/droidwall/
    CMDProcessorLibrary
    Pimp_my_Z1
    HoloGraphLibrary
    程序猿正本清源式进化的意义
    UnsatisfiedLinkError: No implementation found for , AndroidStudio使用*.so
    HUNNU-10307-最优分解问题
    Spring声明式事务
    【献给CWNU的师弟】Web篇
    迪科斯彻算法总结
  • 原文地址:https://www.cnblogs.com/bjdx1314/p/11429757.html
Copyright © 2011-2022 走看看