2013-12-13 106 views
0

我在特定時間使用JavaScript代碼進行刷新。我想在特定的時間和日期刷新頁面。我如何在此代碼中添加日期?在特定時間和特定日期刷新頁面

function refreshAt(hours, minutes, seconds, day, month, year) { 
    var now = new Date('<?php echo date("d M Y H:i:s")?>'); 
    var then = new Date('<?php echo date("d M Y H:i:s")?>'); 
    if (now.getHours() > hours || 
     (now.getHours() == hours && now.getMinutes() > minutes) || 
     now.getHours() == hours && now.getMinutes() == minutes && now.getSeconds() >= seconds) { 
     then.setDate(now.getDate() + 1); 
    } 
    then.setDay(day); 
    then.setMonth(month); 
    then.setYear(year); 
    then.setHours(hours); 
    then.setMinutes(minutes); 
    then.setSeconds(seconds); 
    var timeout = (then.getTime() - now.getTime()); 
    setTimeout(function() { 
     window.location.reload(true); 
     window.location = "load.php"; 
    }, timeout); 
} 
refreshAt(13, 12, 2013, 21, 25, 00); 
+0

'函數refreshAt(小時,分,秒,日,月,年)'似乎並不匹配' refreshAt(13,12,2013,21,25,00)'很好。 –

+0

我改成refreshAt(22,25,00,13,12,2013);但它的不工作也 – user3099986

+0

任何一個誰可以幫助我? – user3099986

回答

1

我會建議另一種方法,不使用JavaScript(純HTML) :

<meta http-equiv="refresh" content="<?php echo getRemainingSecondsToRefresh() ?>"> 
+0

你是對的,但我怎麼處理它。我的意思是說我想在特定的日期和時間刷新?它的工作如何? – user3099986

+0

這裏有誰能幫助我? – user3099986

+1

您需要在'getRemainingSecondsToRefresh'方法中計算秒數,從'特定日期和時間'中減去'now')。 – falsarella