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);//打印输出就是三天后的日期啦~
     
  • 相关阅读:
    Linux下安装Readis
    windows下的Redis安装:
    解决@ResponseBody不能和 <mvc:annotation-driven>同时使用的问题
    dom4j操作XML
    Ajax优缺点
    来一打前端博客压压惊
    tinypng upload一键压缩上传工具,告别人肉
    手把手教你撸一个简易的 webpack
    前端路由简介以及vue-router实现原理
    JS 数据类型、赋值、深拷贝和浅拷贝
  • 原文地址:https://www.cnblogs.com/bjdx1314/p/11429757.html
Copyright © 2011-2022 走看看