js 判断当前时间是否在规定的时间内

服务器返回的数据
js 判断当前时间是否在规定的时间内

    dayFlag() {
      let H = new Date().getHours();
      // 在区间
      if (
        H > this.detail.weekBeginTime.split(":")[0] &&
        H < this.detail.weekEndTime.split(":")[0]
      ) {
        return true;
      }

      // 等于开始时间的小时
      if (
        H == this.detail.weekBeginTime.split(":")[0] &&
        H != this.detail.weekEndTime.split(":")[0]
      ) {
        // 判断分钟
        let M = new Date().getMinutes();

        if (M > this.detail.weekBeginTime.split(":")[1]) {
          return true;
        }

        if (M == this.detail.weekBeginTime.split(":")[1]) {
          // 判断s
          let S = new Date().getSeconds();
          if (S >= this.detail.weekBeginTime.split(":")[2]) {
            return true;
          }
        }
      }

      // 等于结束时间的小时
      if (
        H == this.detail.weekEndTime.split(":")[0] &&
        H != this.detail.weekBeginTime.split(":")[0]
      ) {
        // 判断分钟
        let M = new Date().getMinutes();

        if (M < this.detail.weekEndTime.split(":")[1]) {
          return true;
        }

        if (M == this.detail.weekEndTime.split(":")[1]) {
          // 判断s
          let S = new Date().getSeconds();
          if (S <= this.detail.weekEndTime.split(":")[2]) {
            return true;
          }
        }
      }

      //  等于 开启时间和结束时间
      if (
        H == this.detail.weekBeginTime.split(":")[0] &&
        H == this.detail.weekEndTime.split(":")[0]
      ) {
        let M = new Date().getMinutes();
        // 分钟 在开始时间和结束时间之间
        if (
          M < this.detail.weekEndTime.split(":")[1] &&
          M > this.detail.weekBeginTime.split(":")[1]
        ) {
          return true;
        }
        //等于 开启时间和结束时间
        if (
          M == this.detail.weekEndTime.split(":")[1] &&
          M == this.detail.weekBeginTime.split(":")[1]
        ) {
          let S = new Date().getSeconds();
          if (
            S > this.detail.weekBeginTime.split(":")[2] &&
            S < this.detail.weekEndTime.split(":")[2]
          ) {
            return true;
          }
        }

        if (
          M == this.detail.weekEndTime.split(":")[1] &&
          M != this.detail.weekBeginTime.split(":")[1]
        ) {
          let S = new Date().getSeconds();
          console.log(S, "是s");
          if (S <= this.detail.weekEndTime.split(":")[2]) {
            return true;
          }
        }

        if (
          M != this.detail.weekEndTime.split(":")[1] &&
          M == this.detail.weekBeginTime.split(":")[1]
        ) {
          let S = new Date().getSeconds();
          if (S >= this.detail.weekBeginTime.split(":")[2]) {
            return true;
          }
        }
      }

      return false;
    },
上一篇:pandas dataframe 一列数据变多列


下一篇:split的用法