Home » Jquery » javascript – Countdown works on localhost but on webserver shows wrong date-Exceptionshub

javascript – Countdown works on localhost but on webserver shows wrong date-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I have a countdown working perfect on my local host but on webserver it gives wrong date.
on local host it gives me 5 days and few hours remaining, but on webserver it gives me -271 days and few hours

<div class="col-md-6 pb-4 pb-lg-0 col-lg-4">
<div class="text">
<div id="timer" class="d-flex mb-0">
<div class="time pl-3" id="days"></div>    
<div class="time pl-3" id="hours"></div>
<div class="time pl-3" id="minutes"></div>
<div class="time pl-3" id="seconds"></div>
</div>


$('.checkin_date, .checkout_date').datepicker({
  'format': 'm/d/yyyy',
  'autoclose': true
});


function makeTimer() {

    var endTime = new Date("21 February 2020 7:00:00 GMT+01:00");           
    endTime = (Date.parse(endTime) / 1000);

    var now = new Date();
    now = (Date.parse(now) / 1000);

    var timeLeft = endTime - now;

    var days = Math.floor(timeLeft / 86400); 
    var hours = Math.floor((timeLeft - (days * 86400)) / 3600);
    var minutes = Math.floor((timeLeft - (days * 86400) - (hours * 3600 )) / 60);
    var seconds = Math.floor((timeLeft - (days * 86400) - (hours * 3600) - (minutes * 60)));

    if (hours < "10") { hours = "0" + hours; }
    if (minutes < "10") { minutes = "0" + minutes; }
    if (seconds < "10") { seconds = "0" + seconds; }

    $("#days").html(days + "<span>Days</span>");
    $("#hours").html(hours + "<span>Hours</span>");
    $("#minutes").html(minutes + "<span>Minutes</span>");
    $("#seconds").html(seconds + "<span>Seconds</span>");       

}

setInterval(function() { makeTimer(); }, 1000);



})(jQuery);
How to&Answer:

Your server probably has a wrong date