This below code runs perfectly on desktop Chrome, but doesn't return the countdown properly on mobile Chrome (iPhone). Checked in Safari too, same result. It's a simple jQuery
countdown. The script itself runs since the innerHTML
is set after all, just with not the proper data. Also, I confirmed that getTime()
is also correct. What can possibly be the difference?
Desktop
$(document).ready(function() {
$(".cd").each(function(index, obj) {
var countDownDate = new Date(obj.getAttribute('value'));
var x = setInterval(function() {
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);
obj.innerHTML = days + "d " + hours + "h " +
minutes + "m " + seconds + "s ";
if (distance < 0) {
clearInterval(x);
obj.innerHTML = "EXPIRED";
}
}, 1000);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="demo" class="cd" value="2018-06-10 18:00:00"></p>
<p id="demo2" class="cd" value="2018-06-11 18:00:00"></p>