自2天以来,我的倒计时一直很好,但是现在我遇到了一个奇怪的问题。
脚本一直在显示GRB已完成,而不是一直运行倒计时,直到应该在星期日的晚上9点至10PM +8 GMT为止。
有人能指出我正确的方向吗,我尽了一切努力,但我不明白为什么它可以告诉我。 我还尝试查看控制台上是否有错误,但没有。
您可以在我的网站上看到它: http://shaiyaunite.org
这是整个脚本:
jQuery(document).ready(function(jq){
// Update the count down every 1 second
var x = setInterval(function() {
// Get todays date and time
var d = new Date(Date.now());
// Passer en UTC
d.setMinutes(d.getMinutes() + d.getTimezoneOffset());
// Repasser en n'importe timezone (même si là, c'est plus intelligent de changer le script pour rester en UTC) :
d.setMinutes(d.getMinutes() + 8 * 60); // Ici GMT + 8, attention toutefois au DST s'il y en a dans ta timezone
var countDownDate = getNextDayOfWeek(d,0,21);
// Find the distance between now an the count down date
var distance = countDownDate - d;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24)).toString();
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)).toString();
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)).toString();
var seconds = Math.floor((distance % (1000 * 60)) / 1000).toString();
// Add 0 when value are < 10
hours = (hours < 10) ? "0"+hours : hours;
minutes = (minutes < 10) ? "0"+minutes : minutes;
seconds = (seconds < 10) ? "0"+seconds : seconds;
var grb = jq("#grb");
// Display the result in the element with id="grb"
grb.html(days + "d " + hours + "h " + minutes + "m " + seconds + "s");
// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
var one_hour = -60 * -60 * -1000;
if(distance < one_hour){
grb.html("GRB is finished!");
}else{
grb.html("GRB is open!");
}
}
}, 1000);
function getTextMonth(month){
switch(month){
case 1:
month = "January";
break;
case 2:
month = "February";
break;
case 3:
month = "March";
break;
case 4:
month = "April";
break;
case 5:
month = "May";
break;
case 6:
month = "June";
break;
case 7:
month = "July";
break;
case 8:
month = "August";
break;
case 9:
month = "September";
break;
case 10:
month = "October";
break;
case 11:
month = "November";
break;
case 12:
month = "December";
break;
}
return month;
function getNextDayOfWeek(date, dayOfWeek, hour) {
var resultDate = new Date(Date.now());
resultDate.setDate(date.getDate() + (7 + dayOfWeek - date.getDay()) % 7);
resultDate.setHours(hour,0,0,0);
return resultDate;
谢谢!