首页 > 其他分享 >js判断时间区间是否重叠

js判断时间区间是否重叠

时间:2022-12-02 16:33:45浏览次数:38  
标签:11 00 const 重叠 29 js 2022 区间 et

   <script>
      const range = [
        {
          st: "2022-11-29 10:00",
          et: "2022-11-29 11:00",
        },
        {
          st: "2022-11-29 15:00",
          et: "2022-11-29 19:00",
        },
      ];

      const startTime = new Date("2022-11-29 16:00").getTime();
      const endTime = new Date("2022-11-29 17:00").getTime();

      let flag = true;
      for (let index in range) {
        const st = new Date(range[index]["st"]).getTime();
        const et = new Date(range[index]["et"]).getTime();
        if (endTime <= st || startTime >= et) {
        } else {
          flag = false;
          break;
        }
      }
      if (flag == false) alert("时间区间重叠");
    </script>

 

标签:11,00,const,重叠,29,js,2022,区间,et
From: https://www.cnblogs.com/caroline2016/p/16944848.html

相关文章