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