【问题标题】:I want to run the countdown every 30 minutes, how can that be done?我想每 30 分钟倒计时一次,怎么做?
【发布时间】:2022-01-16 14:03:55
【问题描述】:

我想在下面的代码中每 30 分钟运行一次倒计时,倒计时应该每 30 分钟运行一次。

function createCountDown(elementId, sec) {
        var tms = sec;
        var x = setInterval(function() {
            var distance = tms*1000;
            var days = Math.floor(distance / (1000 * 60 * 60 * 24));
            var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
            var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
            var seconds = Math.floor((distance % (1000 * 60)) / 1000);
            document.getElementById(elementId).innerHTML =days+"d: "+ hours + "h "+ minutes + "m " + seconds + "s ";
            if (distance < 0) {
                clearInterval(x);
                document.getElementById(elementId).innerHTML = "{{__('COMPLETE')}}";
            }
            tms--;
        }, 1000);
    }
  createCountDown('counter', {{\Carbon\Carbon::tomorrow()->diffInSeconds()}});
  }
}
};

【问题讨论】:

    标签: javascript timestamp countdown


    【解决方案1】:

    您可以使用setInterval()

    setInterval(function () {
       // Run your countdown script
       ....
    }, 1800000)
    
    // 1800000 // miliseconds = 30 minutes
    

    【讨论】:

      猜你喜欢
      • 2016-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-30
      • 1970-01-01
      • 1970-01-01
      • 2020-06-12
      • 1970-01-01
      相关资源
      最近更新 更多