首页 > Web开发 > 详细

js 倒计时

时间:2020-07-30 21:06:07      阅读:66      评论:0      收藏:0      [点我收藏+]

今天在修改之前一位老哥留下的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);

 

js 倒计时

原文:https://www.cnblogs.com/hello-dummy/p/13405461.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!