1

The goal is to have the countdown timer to count down to a specific time in NYC (EST). So the the timer goes to zero at 12:00 in NYC but in LA it would go to zero at 09:00

This is the code I use from W3Schools. But I don't have enough knowledge to add the timezone.

Can anyone help please :)

<script>
// Set the date we're counting down to
var countDownDate = new Date("Dec, 2019 12:00:00 GMT-0500").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

  // Get today's date and time
  var now = new Date().getTime();

  // Find the distance between now and the count down date
  var distance = countDownDate - now;

  // Time calculations for days, hours, minutes and seconds
  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);

  // Output the result in an element with id="demo"
  document.getElementById("demo").innerHTML = hours + "h "
  + minutes + "m " + seconds + "s ";

  // If the count down is over, write some text 
  if (distance < 0) {
    clearInterval(x);
    document.getElementById("demo").innerHTML = "EXPIRED";
  }
}, 1000);
</script>
Ruben
  • 11
  • 3
  • 2
    Does this answer your question? [How to initialize a JavaScript Date to a particular time zone](https://stackoverflow.com/questions/15141762/how-to-initialize-a-javascript-date-to-a-particular-time-zone) – Hamms Nov 21 '19 at 20:51
  • Thank you Hamms :) It probably does :p but I'm not sure what to use. And the post is also almost 7 year old, but not sure if that matters? I looked at that one, and for what I understand its this one I should use: ``` new Date('Feb 28 2013 19:00:00 GMT-0500') – Ruben Nov 22 '19 at 14:12
  • Hi @Hamms. I got it to work on desktop by adding GMT-0500 after Date. See updated code. But its not working on mobile. I get a NaN for were the countdown should be. Any suggestions? – Ruben Nov 27 '19 at 14:04

0 Answers0