2

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?

4

2 回答 2

1

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

于 2015-04-10T09:49:19.460 回答
0

you can get utc datetime by

var d = new Date();
var n = d.toUTCString();

will display Fri, 10 Apr 2015 09:37:31 GMT.

$('#counting-down').countdown(d.toUTCString(), 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>'
));

});

Hope this what you needed.

于 2015-04-10T09:40:20.707 回答