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

2
  • Where is GetTime? I can't find Commented Sep 14, 2021 at 18:18
  • @testing_22 its built in javascript function Commented Sep 14, 2021 at 18:19

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.