jQuery.countdown icon indicating copy to clipboard operation
jQuery.countdown copied to clipboard

How should set since date or sync with server time?

Open davidemiceli opened this issue 10 years ago • 10 comments

Hi, a simple question...

There is a way to set the start date? There is some parameter as "since:" to set the server datetime (for server syncronization)? How could I do? Is it possible?

Thanks for a response!

davidemiceli avatar Sep 11 '15 20:09 davidemiceli

Yes i also have same issue, need to sync it with server.

gouravkhanna avatar Sep 18 '15 06:09 gouravkhanna

Ok, thanks!

davidemiceli avatar Sep 18 '15 10:09 davidemiceli

+1, this really needs a "now" param to pass server time as the definitive time, otherwise the user's browser could be a long way out of sync.

wheelsandcogs avatar Sep 29 '15 15:09 wheelsandcogs

Hello & thanks for this great plugin.

I have the same issue whereabouts the user fudges with their PC clock (e.g sets it an hour behind) and then the countdown becomes misleading.

Works well with different time zones but not when the local system time is tampered with.

Are you planning in the near future to provide an enhancement to this, i.e. to subtract the time remaining from an accurate date? Eg. a server date/time?

Cheers

vogatsiko avatar Sep 30 '15 18:09 vogatsiko

Duplicated #119.

Even if does, it won't solve the problem because user always can screw with his machine date. The suggested approach is to make an AJAX call to some endpoint that retrieve the correct offset and reset the countdown!

var $clock = $("#clock").on('update.countdown', function(event) { /* ... */ });
// Sync with the server time
$.get("http://myhost.com/server-time", {userMachineDate: new Date()}, function(data) {
    var serverTimeOffset = new Date(data);
    $clock.countdown(serverTimeOffset);
});

hilios avatar Oct 08 '15 15:10 hilios

But why we can't initialize plugin with remaining milliseconds instead of final date value? Remaining seconds we can get from server, local time shouldn't affect on countdown in this case.

LordotU avatar Feb 19 '16 14:02 LordotU

@LordotU that's a nice idea!

hilios avatar Feb 21 '16 14:02 hilios

@hilios your solutions is never work.

vietnguyen09 avatar Aug 30 '16 08:08 vietnguyen09

//get the remaining time from server side
//then set the endDate be equals to local time + remaining time;
//here's my solution

var remainingTime;  //in milliseconds,get from server side
var endDate = new Date(Date.parse(new Date()) +remainingTime );

$(' .count_down').countdown(endDate ), function(event) {
	// your code here	
});



JashonWang avatar Oct 25 '17 03:10 JashonWang

//get the remaining time from server side
//then set the endDate be equals to local time + remaining time;
//here's my solution

var remainingTime;  //in milliseconds,get from server side
var endDate = new Date(Date.parse(new Date()) +remainingTime );

$(' .count_down').countdown(endDate ), function(event) {
	// your code here	
});

var endDate = Date.now() + remainingTime;

Ishodnikov avatar Nov 25 '18 18:11 Ishodnikov