したがって、このスクリプト ( http://www.rmkwebdesign.com/Countdown_Timers/Repeating_Daily_Timer.htmlのクレジット) は、基本的に Javascript の毎日のカウントダウンです。getDate 変数を getUTCDate に変更しましたが、それでも UTC ではなく、クライアント クロックに依存しています。これを修正し、クライアント側のコンピューターの時刻に依存しないようにして、クライアントのコンピューターの時刻が間違っている場合にカウントダウンが正しく表示されないようにするにはどうすればよいですか?? ありがとう。
JavaScriptコードは次のとおりです。
<script type="text/javascript">
var current = "Test";
var startHour = 0;
var startMinute = 0;
var endHour = 23;
var endMinute = 55;
var tz = 0;
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
if (startMinute < 10){startMinute = "0" + startMinute;}
function countdown()
{
var today=new Date();
var todayy=today.getYear();
if (todayy < 1000)
{todayy += 1900;}
var todaym = today.getUTCMonth();
var todayd = today.getUTCDate();
var todayh = today.getUTCHours();
var todaymin = today.getUTCMinutes();
var todaysec = today.getUTCSeconds();
// add a zero in front of numbers<10
todaymin = checkTime(todaymin);
todaysec = checkTime(todaysec);
var startString = parseInt(startHour + "" + startMinute + "00");
var nowString1 = montharray[todaym] + " " + todayd + ", " + todayy + " " + todayh + ":" + todaymin + ":" + todaysec;
var nowString = Date.parse(nowString1) + (tz*1000*60*60);
var nowTime = parseInt(todayh + "" + todaymin + "" + todaysec);
var endString1 = (montharray[todaym] + " " + todayd + ", " + todayy + " " + endHour + ":" + endMinute);
var endString = Date.parse(endString1) - (today.getTimezoneOffset() * (1000*60));
var dd = endString - nowString;
var dday = Math.floor(dd/(60*60*1000*24)*1);
var dhour = Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
var dmin = Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
var dsec = Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
if ((dhour <= 0 && dmin <= 0 && dsec <= 0) || (nowTime < startString))
{
document.getElementById('count2').innerHTML = current;
document.getElementById('count2').style.display = "inline";
document.getElementById('count2').style.width = "390px";
document.getElementById('dhour').style.display = "none";
document.getElementById('dmin').style.display = "none";
document.getElementById('dsec').style.display = "none";
document.getElementById('hours').style.display = "none";
document.getElementById('minutes').style.display = "none";
document.getElementById('seconds').style.display = "none";
setTimeout("countdown()",500);
return;
}
else
{
document.getElementById('count2').style.display = "none";
document.getElementById('dhour').style.display = "inline";
document.getElementById('dmin').style.display = "inline";
document.getElementById('dsec').style.display = "inline";
document.getElementById('hours').style.display = "inline";
document.getElementById('minutes').style.display = "inline";
document.getElementById('seconds').style.display = "inline";
document.getElementById('dhour').innerHTML = dhour;
document.getElementById('dmin').innerHTML = dmin;
document.getElementById('dsec').innerHTML = dsec;
setTimeout("countdown()",500);
}
if (dhour < 2 || (dhour == 2 && dmin == 0 && dsec == 0))
{
document.getElementById('dhour').style.color = "yellow";
document.getElementById('dmin').style.color = "yellow";
document.getElementById('dsec').style.color = "yellow";
}
if (dhour < 1 || (dhour == 1 && dmin == 0 && dsec == 0))
{
document.getElementById('dhour').style.color = "red";
document.getElementById('dmin').style.color = "red";
document.getElementById('dsec').style.color = "red";
}
}
function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
</script>