PHP實(shí)現(xiàn)倒計時功能
本文實(shí)例為大家分享了PHP實(shí)現(xiàn)倒計時功能的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html><html><head> <title>PHP實(shí)現(xiàn)倒計時功能</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é)束了,考試時間是:{$starttimestr}至{$endtimestr}'); } if ($endtime >= $nowtime) { $lefttime = $endtime - $nowtime; //實(shí)際剩下的時間(秒) } else { $lefttime = 0; exit('考試已經(jīng)結(jié)束!'); }?><p>考試開始時間:<?php echo $starttimestr; ?></p><p>考試結(jié)束時間:<?php echo $endtimestr; ?></p><p> 距離考試結(jié)束還有: <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(’考試結(jié)束了!’); location.reload(); } } onload = function() { GetRTime(); }</script></body></html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP基礎(chǔ)知識VBScript基本元素講解2. ajax請求添加自定義header參數(shù)代碼3. Python requests庫參數(shù)提交的注意事項(xiàng)總結(jié)4. IntelliJ IDEA導(dǎo)入jar包的方法5. Kotlin + Flow 實(shí)現(xiàn)Android 應(yīng)用初始化任務(wù)啟動庫6. 詳談ajax返回數(shù)據(jù)成功 卻進(jìn)入error的方法7. 使用Python和百度語音識別生成視頻字幕的實(shí)現(xiàn)8. 使用python 計算百分位數(shù)實(shí)現(xiàn)數(shù)據(jù)分箱代碼9. python操作mysql、excel、pdf的示例10. vue-electron中修改表格內(nèi)容并修改樣式
