【问题标题】:Refresh page at specific time and specific date [duplicate]在特定时间和特定日期刷新页面[重复]
【发布时间】:2013-12-13 17:15:06
【问题描述】:

我正在使用 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);

【问题讨论】:

  • function refreshAt(hours, minutes, seconds, day, month, year) 似乎与refreshAt(13,12,2013,21,25,00) 不太匹配。
  • 我改为 refreshAt(22,25,00,13,12,2013);但它也不起作用
  • 这里有谁能帮助我吗?
  • 不要发布重复的问题。您已经在几个小时前发布了这个问题。

标签: javascript php html refresh


【解决方案1】:

我会推荐另一种方法,无需 JavaScript(纯 HTML):

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

【讨论】:

  • 你是对的,但我怎么能处理它。我的意思是说我想在特定的日期和时间刷新?它是如何工作的?
  • 这里有谁能帮助我吗?
  • 您需要在getRemainingSecondsToRefresh 方法中计算秒数,从specific date and time 中减去now)。
猜你喜欢
  • 2012-02-05
  • 2016-03-27
  • 2021-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-08
  • 1970-01-01
  • 2018-12-06
相关资源
最近更新 更多