2015-10-21 53 views
2

我在尋找一個帶可調時區的javascript倒數計時器,並發現這個腳本叫做tzcount.js。根據該指令:時區倒計時腳本,不按預期工作?

月份可以指定爲1到12之間的數字來表示 哪個,你是倒計時(年的月它將承擔 明年如果一個月內已經過去的今年

用於但當我輸入值1個月,該腳本告訴我,日期已過,而不是假設它是未來一年的第一個月。我是否錯過了一些東西,或者這個腳本沒有按照預期工作?

完整的腳本:

<!--Copy and paste just above the close </BODY> of you HTML webpage.--> 

<SCRIPT type="text/javascript"> 

// **** Time Zone Count Down Javascript **** // 
/* 
Visit http://rainbow.arch.scriptmania.com/scripts/ 
for this script and many more 
*/ 

////////// CONFIGURE THE COUNTDOWN SCRIPT HERE ////////////////// 

var month = '*';  // '*' for next month, '0' for this month or 1 through 12 for the month 
var day = '1';  // Offset for day of month day or + day 
var hour = 0;  // 0 through 23 for the hours of the day 
var tz = -5;   // Offset for your timezone in hours from UTC 
var lab = 'tzcd'; // The id of the page entry where the timezone countdown is to show 

function start() {displayTZCountDown(setTZCountDown(month,day,hour,tz),lab);} 

    // ** The start function can be changed if required ** 
window.onload = start; 

////////// DO NOT EDIT PAST THIS LINE ////////////////// 

function setTZCountDown(month,day,hour,tz) 
{ 
var toDate = new Date(); 
if (month == '*')toDate.setMonth(toDate.getMonth() + 1); 
else if (month > 0) 
{ 
if (month <= toDate.getMonth())toDate.setYear(toDate.getYear() + 1); 
toDate.setMonth(month-1); 
} 
if (day.substr(0,1) == '+') 
{var day1 = parseInt(day.substr(1)); 
toDate.setDate(toDate.getDate()+day1); 
} 
else{toDate.setDate(day); 
} 
toDate.setHours(hour); 
toDate.setMinutes(0-(tz*60)); 
toDate.setSeconds(0); 
var fromDate = new Date(); 
fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset()); 
var diffDate = new Date(0); 
diffDate.setMilliseconds(toDate - fromDate); 
return Math.floor(diffDate.valueOf()/1000); 
} 
function displayTZCountDown(countdown,tzcd) 
{ 
if (countdown < 0) document.getElementById(tzcd).innerHTML = "Sorry, you are too late."; 
else {var secs = countdown % 60; 
if (secs < 10) secs = '0'+secs; 
var countdown1 = (countdown - secs)/60; 
var mins = countdown1 % 60; 
if (mins < 10) mins = '0'+mins; 
countdown1 = (countdown1 - mins)/60; 
var hours = countdown1 % 24; 
var days = (countdown1 - hours)/24; 
document.getElementById(tzcd).innerHTML = days + " day" + (days == 1 ? '' : 's') + ' + ' +hours+ 'h : ' +mins+ 'm : '+secs+'s'; 
setTimeout('displayTZCountDown('+(countdown-1)+',\''+tzcd+'\');',999); 
} 
} 
</SCRIPT> 
<p><font face="arial" size="-2">The countdown script at </font><br><font face="arial, helvetica" size="-2"><a href="http://rainbow.arch.scriptmania.com/scripts/">Rainbow Arch</a></font></p> 

我找到了腳本,說明,這裏http://rainbow.arch.scriptmania.com/scripts/timezone_countdown.html

回答

1

該腳本不工作的權利。

你需要編輯這一行:

if (month <= toDate.getMonth())toDate.setYear(toDate.getYear() + 1); 

getYear簡寫,所以今年會返回115。 setYear然後認爲你的意思是115公元,它通過時間前。

setYeargetYear替換爲setFullYeargetFullYear。這些功能將返回/期望2015.

+0

像發條一樣,謝謝。 – Stim

+1

Pun是打算? :P – Scimonster