php倒计时器基于文件修改时间

时间:2021-05-18 01:02:01

I have a file on our server that gets overwritten every 10 minutes with an updated file called AgentReport.html

我的服务器上有一个文件,每10分钟被一个名为AgentReport.html的更新文件覆盖

I have a webpage that uses an iframe to display the AgentReport.html with a meta refresh set to 60 seconds.

我有一个网页,使用iframe显示AgentReport.html,元刷新设置为60秒。

I am trying to create a basic php countdown timer to display how long until the next update using filemtime to grab the minutes of the last modified date for AgentReport.html.

我正在尝试创建一个基本的php倒计时计时器,以显示使用filemtime下次更新的时间,以获取AgentReport.html上次修改日期的分钟数。

Here is what I have so far:

这是我到目前为止:

<?php

$nextUpdate = date ("i", filemtime("AgentReport.html")) + 10;
$currtime = date ("i");
$remaining = ($nextUpdate - $currtime - 1);
if ($remaining >= 60) {
    $remaining = ($remaining - 60) . "minutes";
}
else if ($remaining <= 1) {
    $remaining = "a minute";
}
else $remaining = $remaining . " minutes";
echo "Next update in about " . $remaining;

?>

This is sloppy but almost works.. but I am getting confused. I am having a hard time navigating the turn of an hour (report seems to hit the server at say 10:52) and handling the last minute so it displays properly.

这很草率但几乎可以工作..但我感到困惑。我很难在一小时之内导航(报告似乎在服务器上说是10:52)并处理最后一分钟以便正确显示。

Any ideas?

1 个解决方案

#1


<?php
$nextUpdate = filemtime("AgentReport.html") + 10*60;
$currTime   = time();
$min        = (int)(($nextUpdate-$currTime)/60);
echo 'Next update in about '.($min <= 1 ? 'a minute' : $min.' minutes');
?>

#1


<?php
$nextUpdate = filemtime("AgentReport.html") + 10*60;
$currTime   = time();
$min        = (int)(($nextUpdate-$currTime)/60);
echo 'Next update in about '.($min <= 1 ? 'a minute' : $min.' minutes');
?>