PHP實(shí)現(xiàn)倒計(jì)時(shí)功能
本文實(shí)例為大家分享了PHP實(shí)現(xiàn)倒計(jì)時(shí)功能的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html> <head> <title>PHP實(shí)現(xiàn)倒計(jì)時(shí)功能</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("考試已經(jīng)結(jié)束了,考試時(shí)間是:{$starttimestr}至{$endtimestr}"); } if ($endtime >= $nowtime) { $lefttime = $endtime - $nowtime; //實(shí)際剩下的時(shí)間(秒) } else { $lefttime = 0; exit("考試已經(jīng)結(jié)束!"); } ?> <p>考試開(kāi)始時(shí)間:<?php echo $starttimestr; ?></p> <p>考試結(jié)束時(shí)間:<?php echo $endtimestr; ?></p> <p> 距離考試結(jié)束還有: <span id="RemainD"></span> 天 <span id="RemainH"></span> 小時(shí) <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('考試結(jié)束了!'); location.reload(); } } onload = function() { GetRTime(); } </script> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
php實(shí)現(xiàn)多維數(shù)組排序的方法示例
這篇文章主要介紹了php實(shí)現(xiàn)多維數(shù)組排序的方法,結(jié)合實(shí)例形式分析了php針對(duì)多維數(shù)組的排序操作相關(guān)技巧,需要的朋友可以參考下2017-03-03PHP實(shí)現(xiàn)基數(shù)排序的方法詳解
這篇文章主要介紹了PHP實(shí)現(xiàn)基數(shù)排序的方法,結(jié)合實(shí)例形式分析了基數(shù)排序的原理、實(shí)現(xiàn)方法與相關(guān)操作技巧,需要的朋友可以參考下2017-12-12php中$_SERVER[PHP_SELF] 和 $_SERVER[SCRIPT_NAME]之間的區(qū)別
php中$_SERVER[PHP_SELF] 和 $_SERVER[SCRIPT_NAME]之間的區(qū)別2009-09-09Json_encode防止?jié)h字轉(zhuǎn)義成unicode的方法
json_encode通常會(huì)把json中的漢字轉(zhuǎn)義成unicode,但是有些時(shí)候不是我們想要的,下面小編給大家介紹json_encode防止?jié)h字轉(zhuǎn)義成unicode的方法,需要的朋友參考下吧2016-02-02php獲取遠(yuǎn)程https內(nèi)容時(shí)提示PHP Warning: copy(): Unable&
這篇文章主要介紹了php獲取遠(yuǎn)程https內(nèi)容時(shí)提示PHP Warning: copy(): Unable to find the wrapper “https“ 解決方法,文中通過(guò)代碼和圖文給大家講解的了解決方案,具有一定的參考價(jià)值,需要的朋友可以參考下2024-10-10