取决于你如何实现它。
如果您只读了一次,并依赖于setInterval或/和setTimeout来获得准确性,那么是的..他们可能会失去同步。
如果你总是得到当前在计算中使用的时间,那么它会像系统其他部分不同步一样意味着它跟随计算机的时钟。
改变我的答案在JavaScript/jQuery Countdown添加你
var end = new Date('13 Apr 2012 13:30:00');
var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour *24;
var timer;
function showRemaining()
{
var now = new Date();
var distance = end - now;
if (distance < 0) {
// handle expiry here..
clearInterval(timer); // stop the timer from continuing ..
//alert('Expired'); // alert a message that the timer has expired..
}
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);
var milliseconds = distance % _second;
var countdownElement = document.getElementById('timer');
countdownElement.innerHTML = days + 'd ' +
hours + 'h ' +
minutes + 'm ' +
seconds + 's ' +
milliseconds + 'ms';
}
timer = setInterval(showRemaining, 10);
毫秒但由于需要更复杂的计算,以28-31因子天月和闰年它不处理的月份和年份..
演示在http://jsfiddle.net/TaHtz/2/
http://stackoverflow.com/questions/8067488/how-to-show-milliseconds-in -count-down-timer-javascript – Ghokun 2012-04-11 19:29:06
是的,这是事实,他们变得不同步。作为一名系统管理员,我知道计算机时钟可以在短短几周内完成(10秒或20秒)。几个月后,他们会在几分钟内得到解脱。定期同步到标准时间服务器很重要。因此,制作基于JavaScript的计数将取决于计算机时钟的准确性。 – 2012-04-11 19:45:36
既然你想在很多天,甚至是几周或几个月的时间内倒数,你想在哪里运行这个程序?在Web服务器上?在你的台式电脑上?在手机上? – 2012-04-11 19:48:32