PHP实现倒计时功能
本文实例为大家分享了PHP实现倒计时功能的具体代码,供大家参考,具体内容如下
<!DOCTYPE html> <html> <head> <title>PHP实现倒计时功能</title> </head> <body> <?php date_default_timezone_set('PRC'); $starttimestr = date('Y-m-d H:i:s', strtotime('now')); $starttimestr= mktime(0,0,0,7,7,2020); //$endtimestr = date('Y-m-d H:i:s', strtotime('+18 hours 1 minutes')); $endtimestr = mktime(18,0,0,date('m'),date('d'),date('Y')); $starttime = strtotime($starttimestr); $endtime = strtotime($endtimestr); $nowtime = time(); if ($nowtime < $starttime) { exit("考试已经结束了,考试时间是:{$starttimestr}至{$endtimestr}"); } if ($endtime >= $nowtime) { $lefttime = $endtime - $nowtime; //实际剩下的时间(秒) } else { $lefttime = 0; exit("考试已经结束!"); } ?> <p>考试开始时间:<?php echo $starttimestr; ?></p> <p>考试结束时间:<?php echo $endtimestr; ?></p> <p> 距离考试结束还有: <span id="RemainD"></span> 天 <span id="RemainH"></span> 小时 <span id="RemainM"></span> 分钟 <span id="RemainS"></span> 秒 </p> <script type="text/javascript"> var runtimes = 0; function GetRTime() { var lefttime = <?php echo $lefttime; ?> * 1000 - runtimes * 1000; if (lefttime >= 0) { var nD = s.floor(lefttime / (1000 * 60 * 60 * 24)) % 24; var nH = Math.floor(lefttime / (1000 * 60 * 60)) % 24; var nM = Math.floor(lefttime / (1000 * 60)) % 60; var nS = Math.floor(lefttime / 1000) % 60; document.getElementById("RemainD").innerHTML = nD; document.getElementById("RemainH").innerHTML = nH; document.getElementById("RemainM").innerHTML = nM; document.getElementById("RemainS").innerHTML = nS; runtimes++; setTimeout("GetRTime()", 1000); } else { alert('考试结束了!'); location.reload(); } } onload = function() { GetRTime(); } </script> </body> </html>
相关推荐
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23
savorTheFlavor 2020-10-23