I am writing a HTML embed that displays a countdown for wednesday at 20:30 EST. Everytime it hits that date and time it will set the date to the following wednesday and start counting down the date. The issue is that I am using the .getTime() function to grab the current time. That function will grab the local computer time and I need the script to compare to Eastern Standard Time instead of the local time so the countdown is the same regardless where in the world you are.
Code with .getTime()
<script>
var countDownDate = new Date("Jan 25, 2023 20:30:00").getTime();
var x = setInterval(countdown, 1000);
function countdown(){
var now = new Date().getTime();
var distance = countDownDate - now;
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("days").innerHTML = days;
document.getElementById("hours").innerHTML = hours;
document.getElementById("mins").innerHTML = minutes;
document.getElementById("secs").innerHTML = seconds;
if (distance < 0) {
resetCountdown();
}
}
function resetCountdown(){
clearInterval(x);
var nextWednesday = new Date();
nextWednesday.setDate(nextWednesday.getDate() + (3 + 7 - nextWednesday.getDay()) % 7);
nextWednesday.setHours(20);
nextWednesday.setMinutes(30);
countDownDate = nextWednesday.getTime();
x = setInterval(countdown, 1000);
}
</script>
I tried to use .getUTCDate() and similar functions and wasn't having any luck.
function resetCountdown(){
clearInterval(x);
var nextWednesday = new Date();
nextWednesday.setUTCDate(nextWednesday.getUTCDate() + (3 + 7 - nextWednesday.getUTCDay()) % 7);
nextWednesday.setUTCHours(20);
nextWednesday.setUTCMinutes(30);
countDownDate = nextWednesday.getTime();
x = setInterval(countdown, 1000);
}