【问题标题】:JS stopwatch timer with H:m:s:ms format, the minutes won't reset when it reach 60 minJS秒表计时器,H:m:s:ms格式,分钟到60分钟不重置
【发布时间】:2022-11-15 13:37:49
【问题描述】:

我制作了一个格式为 H:m:s:ms 的 JS 秒表,当它达到 60 分钟时,它总是增加到 61,62,依此类推

我正在使用 setInterval 这是我的代码:

n = 3600;
    td = setInterval(function () 
    {
      n++;
      let hours = parseInt(n / 3600);
      var m = parseInt(n / 60)
      var s = parseInt(n / 60 % 60);
      var M = parseInt(n % 60);

      // let hours = Math.floor(((n[ids] / 1000) / 60) / 60) % 24
      // let m = Math.floor((n[ids] / 1000) / 60) % 60
      // let s = Math.floor(n[ids] / 1000) % 60
      // let M = Math.floor(n[ids] % 1000)

      $("#display0").html(toDub(hours) + ":" + toDub(m) + ":" + toDub(s) + ":" + toDub(M))
    }, 1000 / 60);

完整的源代码https://jsfiddle.net/greycat/danvL42s/2/

我确定我的有问题多变的。

任何人都可以帮助我吗?

【问题讨论】:

    标签: javascript jquery time


    【解决方案1】:
        n =0;
        td = setInterval(function () 
        {
          n++;
          let hours = parseInt(n / 3600000);
          var m = parseInt(n %3600000 / 60000)
          var s = parseInt(n %3600000 %60000/ 1000);
          var M = parseInt(n %3600000 %60000% 1000);      
          $("#display0").html(toDub(hours) + ":" + toDub(m) + ":" + toDub(s) + ":" + toDub(M));
          if(m==60){
            n=0;
          }
        }, 1);
    

    【讨论】:

      猜你喜欢
      • 2012-12-30
      • 1970-01-01
      • 2011-10-20
      • 2015-03-23
      • 2019-11-24
      • 1970-01-01
      • 2012-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多