0

I'm using a countdown script that is not working on pad and phones. It shows up as NaN.

Any clue to why? :)

I have to write more text for some reason and not sure what to say. So you can ignore this. Just so its possible to post this

<!-- START COUNTDOWN TIMER -->

<script>
// Set the date we're counting down to
var countDownDate = new Date("Dec 08, 2019 24: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 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);

  // Output the result in an element with id="demo"
  document.getElementById("demo").innerHTML = days + " days remaining";

  // If the count down is over, write some text 
  if (distance < 0) {
    clearInterval(x);
    document.getElementById("demo").innerHTML = "EXPIRED";
  }
}, 1000);
</script>

<!-- END COUNTDOWN TIMER -->
```
Krupal Panchal
  • 1,553
  • 2
  • 13
  • 26
Ruben
  • 11
  • 3
  • how are you running this program on your phone? – Enrico Cortinovis Nov 29 '19 at 15:26
  • 1
    What mobile browsers are you seeing this behavior in? I know there are some issues with Safari (and other mobile browsers on iPhone since they use the Safari engine) ? – DRich Nov 29 '19 at 15:26
  • Yes you are right! :) there is a Safari issue and I think the solution is in this post https://stackoverflow.com/questions/21883699/safari-javascript-date-nan-issue-yyyy-mm-dd-hhmmss/21884244#21884244 But I don't understand how to add this to the code I pasted above. Can you add it to the code so I can copy/paste the whole thing? @DRich – Ruben Nov 29 '19 at 17:23
  • 1
    Stackoverflow is becoming something that you do not have to help for solutions, but provide directly something to be copied and pasted. This is quite sad. – quirimmo Nov 29 '19 at 17:26
  • Does this answer your question? [Safari Javascript Date() NaN Issue (yyyy-MM-dd HH:mm:ss)](https://stackoverflow.com/questions/21883699/safari-javascript-date-nan-issue-yyyy-mm-dd-hhmmss) – Cjmarkham Nov 29 '19 at 17:31
  • This is what you do: Replace: ```var countDownDate = new Date("Dec 08, 2019 24:00:00 GMT-0500").getTime();``` with ```var countDownDate = new Date(Date.UTC(2019, 11, 8, 24, 0, 0)).getTime()+5*3600*1000;``` The new line will work in regular browsers as well as Safari, and is evaluted to the exact same time string. – Sven Nov 29 '19 at 17:54
  • Thank you SO much @Sven! <3 Works great :) Really appreciate the accurate description of what I have to do. Again thank you! – Ruben Nov 29 '19 at 18:09

0 Answers0