137  
查询码:00000850
两个时间戳,倒计时
作者: 郁冲冲 于 2021年05月24日 发布在分类 / 人防组 / 人防前端 下,并于 2021年05月24日 编辑
倒计时

interval(completeTime) {
      console.log("1");
      let _this = this;
      _this.timerCount = setInterval(() => {
        setTimeout(() => {
          let faultDate = new Date().getTime();
          console.log(faultDate);
          let stime = Date.parse(new Date(faultDate));
          let etime = Date.parse(new Date(completeTime));
          //两个时间戳相差的毫秒数
          let timer = etime - stime;
          if (timer > 0) {
            _this.tipShow = true;
            let days = Math.floor(timer / (1000 * 60 * 60 * 24));
            let hours = Math.floor(
              (timer % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)
            );
            let minutes = Math.floor((timer % (1000 * 60 * 60)) / (1000 * 60));
            let seconds = Math.floor((timer % (1000 * 60)) / 1000);
            if (days <= 0) {
              _this.tips = hours + "时" + minutes + "分" + seconds + "秒";
            } else {
              _this.tips =
                days + "天" + hours + "时" + minutes + "分" + seconds + "秒";
            }
            console.log(_this.tips);
            --timer;
          } else {
            _this.tipShow = false;
            clearInterval(_this.timerCount);
          }
        }, 0);
      }, 1000);
    },


 推荐知识

 历史版本

修改日期 修改人 备注
2021-05-24 18:18:16[当前版本] 郁冲冲 调整分类
2021-05-24 18:17:51 郁冲冲 调整分类
2021-05-24 18:17:14 郁冲冲 创建版本

知识分享平台 -V 4.8.7 -wcp