Countdown timer javascript -
how make countdown timer same regardless time on pc. script doesn't work wanted to, can change timer changing date , time on pc.
var end = new date('07/31/2015 4:10 pm'); var _second = 1000; var _minute = _second * 60; var _hour = _minute * 60; var _day = _hour * 24; var timer; function showremaining() { var = new date(); var distance = end - now; if (distance < 0) { clearinterval(timer); document.getelementbyid('giveaway1').innerhtml = 'the winner has been chosen!'; return; } var days = math.floor(distance / _day); var hours = math.floor((distance % _day) / _hour); var minutes = math.floor((distance % _hour) / _minute); var seconds = math.floor((distance % _minute) / _second); document.getelementbyid('giveaway1').innerhtml = days + 'days '; document.getelementbyid('giveaway1').innerhtml += hours + 'hrs '; document.getelementbyid('giveaway1').innerhtml += minutes + 'mins '; document.getelementbyid('giveaway1').innerhtml += seconds + 'secs'; } timer = setinterval(showremaining, 1000);
since local pc time outside control, have reliable time server (or third-party server) @ least once.
once know (correct) server time is, can subtract server time local pc time 'offset' (i.e. difference between server time , local pc time).
once have offset can @ time local pc time - via new date() - , factor in offset 'correct' server time, without having call server each time.
Comments
Post a Comment