Here’s a way to put a counter that updates once a second in a page. It’s based on the time.

This isn’t some earth-shattering discovery, it’s trival. But somebody asked me.

window.setInterval ( function tick () {
  const counter = document.getElementById('counter')
  if (counter) {
    const count = Math.trunc(0.001 * ( - Date.parse('2023-05-30T00:00:00')))
    counter.innerText = count
}, 1000)
<p><span id="counter">123</span> is the count now!</p>

123 is the count now!

Leave a Comment