js 倒计时

今天在修改之前一位老哥留下的bug,就是做一个计时器,然后自己做了一个,顺便记录一下。

代码:

// this.paparTime 为时间戳,秒为单位
//  this.countdownClock 把时间转成00:00:00 的时间字符串格式

const timeOclock = setInterval(() => {
      if (this.paparTime === 0) {clearInterval(timeOclock); }
      const h = Math.floor(this.paparTime / (60 * 60));
      const m = Math.floor((this.paparTime - (h * 60)) / 60);
      const s = this.paparTime % 60;
      this.paparTime = this.paparTime - 1;
      this.countdownClock = (h < 10 ? ('0' + h) : h) + ':' + (m < 10 ? ('0' + m) : m) + ':' + (s < 10 ? ('0' + s) : s);
    }, 1000);
原文地址:https://www.cnblogs.com/hello-dummy/p/13405461.html