0

I am trying to get a countdown working but the issue that is happening is... its looking at both dates in local time... so because of timezones its displaying a different countdown.

The Date.getTime() built-in is supposed to display in UTC but displays in local time instead.

JS:

const second = 1000,
  minute = second * 60,
  hour = minute * 60,
  day = hour * 24;

let countDown = new Date('September 29, 2021 00:00:00').getTime(),
  x = setInterval(function() {

    let now = new Date().getTime(),
      distance = countDown - now;

    document.getElementById('days').innerText = Math.floor(distance / (day)),
      document.getElementById('hours').innerText = Math.floor((distance % (day)) / (hour)),
      document.getElementById('minutes').innerText = Math.floor((distance % (hour)) / (minute)),
      document.getElementById('seconds').innerText = Math.floor((distance % (minute)) / second);
  }, 0)
if (second < 10 && minute < 10 && hour < 10 && day < 10) {
  countDown = "0" + countDown;
}

Demo:

JSFiddle Demo

testing_22
  • 2,340
  • 1
  • 12
  • 28
HeelMega
  • 458
  • 8
  • 23

0 Answers0