1
我有一个倒数计时器,其自H传输时间:I:s到使用这个脚本长版:的Javascript小时倒计时错误
function parseTime() {
var timeLeftStr;
var timeLeft = 0;
timeLeftStr = document.getElementById("timeleft").innerHTML;
timeLeftStr.replace(/(\d+):(\d+):(\d+)/, function() {
for (var i = 1; i < arguments.length - 2; i++) {
// Convert to ms
timeLeft += arguments[i] * Math.pow(60, 3 - i) * 1000;
}
});
countdown(new Date(timeLeft));
}
function countdown(timeLeft) {
var hours = timeLeft.getHours();
var minutes = timeLeft.getMinutes();
var seconds = timeLeft.getSeconds();
if (timeLeft.valueOf() == 0) {
document.getElementById("timeleft").innerHTML = "0 seconds";
window.location = 'home.php?pageid=' + getURLParam("pageid");
return false;
} else {
document.getElementById("timeleft").innerHTML =
(hours == 0 ? "" : hours + (hours == 1 ? " hour" : " hours")) +
(minutes == 0 ? "" : (hours ? (seconds ? ", " : " and ") : " ") + minutes + (minutes == 1 ? " minute" : " minutes")) +
(seconds == 0 ? "" : (hours || minutes ? " and " : "") + seconds + (seconds == 1 ? " second" : " seconds"));
setTimeout(function() { countdown(new Date(timeLeft - 1000)); }, 1000);
}
}
window.onload = parseTime;
的错误是谁住在澳大利亚矿山的用户不断得到错误的“小时” 原定时器会说“23:45:05”,但倒数计时器开始时会显示“10小时45分钟5秒”而非23小时。
任何想法为什么会发生这种情况?谢谢。
我不是那么棒的JS,这是由朋友创建的。
最终解决了它。
我怎样才能使它作为服务器的时间? – 2012-04-02 15:23:56
如何获得服务器时间而不是本地时间? – 2012-04-02 15:27:37
对服务器端资源发回小时,分钟和秒钟进行ajax调用。如果它听起来太复杂了,只需在javascript中使用'getTimezoneOffset()'。请看看这个讨论:http://stackoverflow.com/questions/8805613/javascript-countdown-using-absolute-timezone – fcalderan 2012-04-02 15:31:10