zoukankan      html  css  js  c++  java
  • js 判断所选时间(或者当前时间)是否在某一时间段用于不同时间段显示不同的客服qq

    //qq交谈
    var nowtimes= new Date();
    var starttimes="16:30";
    var endtimes="23:59";
    var timestrings=nowtimes.getHours()+":"+nowtimes.getMinutes();
     function qqchats1(){
         if(!time_range (starttimes,endtimes,timestrings)){
           var list = new Array("2885794580","3001017451");   
         }
         else
         {
            var list = new Array("2885794572","2885794571");         
         }
            var i = fRandomBy(0,1);
            window.location.href = "tencent://message/?uin="+list[i]+"&Site=&menu=yes";
    }function fRandomBy(under, over){ 
       switch(arguments.length){ 
         case 1: return parseInt(Math.random()*under+1); 
         case 2: return parseInt(Math.random()*(over-under+1) + under); 
         default: return 0; 
       }
    }   
    
    var time_range = function (beginTime, endTime, nowTime) {
          var strb = beginTime.split (":");
          if (strb.length != 2) {
              return false;
          }
      
          var stre = endTime.split (":");
          if (stre.length != 2) {
              return false;
         }
     
         var strn = nowTime.split (":");
         if (stre.length != 2) {
             return false;
         }
         var b = new Date ();
         var e = new Date ();
         var n = new Date ();
     
         b.setHours (strb[0]);
         b.setMinutes (strb[1]);
         e.setHours (stre[0]);
         e.setMinutes (stre[1]);
         n.setHours (strn[0]);
         n.setMinutes (strn[1]);
    
        if (n.getTime () - b.getTime () > 0 && n.getTime () - e.getTime () < 0) {
            console.log("当前时间是:" + n.getHours () + ":" + n.getMinutes () + ",");
             return true;
         } else {
            console.log("当前时间是:" + n.getHours () + ":" + n.getMinutes () + ",不在该时间范围内!");
             return false;
        }
     }
  • 相关阅读:
    LeetCode Find Duplicate File in System
    LeetCode 681. Next Closest Time
    LeetCode 678. Valid Parenthesis String
    LeetCode 616. Add Bold Tag in String
    LeetCode 639. Decode Ways II
    LeetCode 536. Construct Binary Tree from String
    LeetCode 539. Minimum Time Difference
    LeetCode 635. Design Log Storage System
    LeetCode Split Concatenated Strings
    LeetCode 696. Count Binary Substrings
  • 原文地址:https://www.cnblogs.com/mumublog/p/6062037.html
Copyright © 2011-2022 走看看