Search code examples
jqueryjquery-countdown

Using jQuery Countdown plugin, how to make the countdown based on the real time (not user's computer time)


I'm using jQuery Countdown plugin. It works fine but when I change the time on my computer, the countdown changes too. I mean the countdown cannot be accurate if the time set on the user's computer is not accurate.

This is how I initiate:

$('#counting-down').countdown('2015/4/25 14:30:00', function(event) {
    var $this = $(this).html(event.strftime(''
        + '<div class="days"> <span>%D</span><label>days</label> </div>'
        + '<div class="hours"> <span>%H</span><label>hours</label> </div>'
        + '<div class="minutes"> <span>%M</span><label>minutes</label> </div>'
        + '<div class="seconds"> <span>%S</span><label>seconds</label> </div>'
    ));
});

any solution to make this countdown based on the real time?


Solution

  • To get the 100% accurate time, you'll need to do a call to a reliable source with an api or use another method. You can do this with either $.ajax . Or by putting code to get the current date in the backend. Even still though, the discrepancy between when you get the time and the time you receive and process this data will still have a slight offset