Reputation: 1357
I have a countdown timer using http://keith-wood.name/countdown.html Jquery Countdown plugin.
There is a problem when the client computer time is not set correctly (ie: out of synched or misconfigures).
Here I would like to achieve a trusted countdown regardless of the client-side time but I couldn't figured out how I can achieve it. (from where I can fetch correct time and how to calculate and offset the correction in the countdown?)
Edit: Let me clarify a little bit more. I do not want milliseconds precision (actually 1 sec precision if enough for me). Also, I do not want to keep client to server synchronized all the time.. I only need to calculate how much client computer time has an offset at the page load. Also I need your help for the modified version of my countdown script.. I can create a JSON API on the backend to serve time if needed (but please guide me what format I shall serve.. My problem is mainly with JS)
Below you can find my countdown time code. I will appreciate any kind of support.
$('#remaining_time').countdown('2020-01-01 00:00:00 +0300')
.on('update.countdown', function(event) {
var format = '%S sn';
if(event.offset.weeks > 0) {
format = '%-w Week +';
} else {
if (event.offset.totalDays > 0) {
format = '%-D Days +';
} else { if (event.offset.totalHours > 0) {
format = '%H Hours, %M min, %S sec';
} else { if (event.offset.totalMinutes > 0) {
format = '%M min, %S sec';
}
}
}
};
$(this).html(event.strftime(format));
})
.on('finish.countdown', function(event) {
$(this).html('Time is Up!');
});
Upvotes: 0
Views: 91