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></span> 天 <span></span> 小时 <span></span> 分钟 <span></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>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/0d57533f716b49eacb0ae080bb9a7dec.html