我在特定时间使用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 :(得分:1)
我会推荐另一种方法,不使用JavaScript(纯HTML):
<meta http-equiv="refresh" content="<?php echo getRemainingSecondsToRefresh() ?>">