php - PHP每30分钟实时倒计时
问题描述
我的老板给了我一个项目,我必须在 PHP 中显示每 30 分钟的实时倒计时任何人都可以帮助我如何做到这一点?对不起,我的英语不好
解决方案
您可以通过简单的方式做到这一点。我已经做到了。
<?php
$time_on =1800;
header( "refresh:$time_on; url=https://localhost/your_project/your_file.php");
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<style type="text/css">
.myClass {
font-family: verdana;
font-size: 16px;
font-weight: normal;
color: black;
line-height: 30px;
}
</style>
</head>
<body>
<script type="text/javascript">
(function () {
var timeLeft = <?php echo $time_on; ?>,
cinterval;
var timeDec = function (){
timeLeft--;
document.getElementById('countdown').innerHTML = timeLeft;
if(timeLeft === 0){
clearInterval(cinterval);
}
};
cinterval = setInterval(timeDec, 1000);
})();
</script>
Redirecting in <span id="countdown"><?php echo floor($time_on); ?></span> seconds.<br><br>
<span class="myClass">Time Start</span>
</body>
</html>
推荐阅读
- python - 找到与文件中的时间戳更接近的时间戳
- microservices - 使用 URL 调用 feign 客户端
- sql - SQL Left Join on Criteria between dates?
- ios - react-native-maps fitToSuppliedMarker/fitToCorodinates 不显示所有标记
- c# - Collectoiview.Filter 不过滤数据
- ios - 如何在 MKMapView Swift 上动画 MKOverlay 的移动
- authentication - Safari 12 和“防止跨站跟踪”模式
- selenium-webdriver - selenium - 使用 count 函数编写 xpath
- python-3.x - i-graph-python 参数等效于 networkx 中的 pos
- delphi - 使用 TStreamReader 和 TStringList 处理非常大的文本文件