4 回答

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超10個(gè)贊
您不能在 PHP 中執(zhí)行此操作,您可以為此類任務(wù)做的是計(jì)算時(shí)間差并以秒為單位并設(shè)置頁(yè)面的標(biāo)題以在時(shí)間差以秒為單位后刷新,如下所示:
<?php
$page = $_SERVER['PHP_SELF'];
$datetime1 = new DateTime('2020-05-23 18:20:10');
$datetime2 = new DateTime('2020-05-23 18:20:30');
$interval = $datetime2->diff($datetime2);
$diff = $datetime2->getTimestamp() - $datetime1->getTimestamp(); // diff in seconds
// you can just have `redirect` queryString params passed like this.
if(empty($_GET['redirect'])) {
? header("Refresh: $diff; url=$page" . "?redirect=1");
}
這里要指出的是,使用標(biāo)記在頁(yè)面中進(jìn)行刷新而不是使用header(),作為實(shí)現(xiàn)對(duì)我來(lái)說(shuō)感覺(jué)更清晰,特別是如果您已經(jīng)有一個(gè)模板引擎:
<meta http-equiv="refresh" content="20">

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超3個(gè)贊
我用的javascript,功能自動(dòng)運(yùn)行
<script>
(function myFunction() {
var time = new Date().getHours()
if( time == "02" ) {
setTimeout(function(){
window.location = 'your url';
}, 5000);
}
})();
</script>

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊
您可以將以下代碼放在標(biāo)題中并進(jìn)行測(cè)試。我希望這有幫助。
if ($time == "03:40:00") {
echo "The new page loading in 10 seconds!";
echo "<meta http-equiv='refresh' content='3'>";
}
注意:上面使用的元標(biāo)記用于定義刷新文檔本身的時(shí)間間隔。根據(jù)需要刷新頁(yè)面,修改元標(biāo)記的“content”屬性中的值

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊
我認(rèn)為這段代碼更好
<script>
function refreshAt(hours, minutes, seconds) {
? ? var now = new Date();
? ? var then = new Date();
? ? 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.setHours(hours);
? ? then.setMinutes(minutes);
? ? then.setSeconds(seconds);
? ? var timeout = (then.getTime() - now.getTime());
? ? setTimeout(function() { window.location.reload(true); }, timeout);
}
refreshAt(16,30,0); //Will refresh the page at 4:30pm
</script>
- 4 回答
- 0 關(guān)注
- 182 瀏覽
添加回答
舉報(bào)