zoukankan      html  css  js  c++  java
  • JS比较当前时间是否在指定时间段内

    function checkTime(stime, etime) {
      //开始时间
      var arrs = stime.split("-");
      var startTime = new Date(arrs[0], arrs[1], arrs[2]);
      var startTimes = startTime.getTime();
      //结束时间
      var arre = etime.split("-");
      var endTime = new Date(arre[0], arre[1], arre[2]);
      var endTimes = endTime.getTime();
      //当前时间
      var thisDate = new Date();
      var thisDates = thisDate.getFullYear() + "-0" + (thisDate.getMonth() + 1) + "-" + thisDate.getDate();
      var arrn = thisDates.split("-");
      var nowTime = new Date(arrn[0], arrn[1], arrn[2]);
      var nowTimes = nowTime.getTime();
      if (nowTimes < startTimes || nowTimes > endTimes) {
        return false;
      }
      return true;
    }
    //用法:
    var timebool=checkTime('2016-8-1','2016-8-10');//注意:日期用“-”分隔
    if(timebool==true){
      document.write('当前日期在指定时间段内');
    }else{
      document.write('当前日期不在指定时间段内');
    }
    反思 空杯 担当
  • 相关阅读:
    视图集
    子类视图
    Mixin扩展类
    GenericAPIView
    APIView
    ModelSerializer使用
    序列化和反序列化
    合并购物车
    pyplot基本绘制
    STL sort “invalid operator <”
  • 原文地址:https://www.cnblogs.com/oralig/p/10007290.html
Copyright © 2011-2022 走看看