PHP 实现简单的 倒计时 时分秒
生活随笔
收集整理的這篇文章主要介紹了
PHP 实现简单的 倒计时 时分秒
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
// 以 YII框架為例: C 層代碼public function actionIndex(){//php的時(shí)間是以秒算。js的時(shí)間以毫秒算
date_default_timezone_set("Asia/Hong_Kong");//地區(qū)//配置每天的活動(dòng)時(shí)間段$starttimestr = "18:53:00";//轉(zhuǎn)換為時(shí)間戳$starttimestr = strtotime($starttimestr);$nowtime = time();$lefttime = $starttimestr-$nowtime; //實(shí)際剩下的時(shí)間(秒)return $this->render('index',['lefttime'=>$lefttime]);} // 以 YII框架為例: C 層代碼public function actionIndex(){//php的時(shí)間是以秒算。js的時(shí)間以毫秒算
date_default_timezone_set("Asia/Hong_Kong");//地區(qū)//配置每天的活動(dòng)時(shí)間段$starttimestr = "18:53:00";//轉(zhuǎn)換為時(shí)間戳$starttimestr = strtotime($starttimestr);$nowtime = time();$lefttime = $starttimestr-$nowtime; //實(shí)際剩下的時(shí)間(秒)return $this->render('index',['lefttime'=>$lefttime]);} //V 層代碼<span class="time" ><span id="RemainH">00</span>時(shí)<span id="RemainM">00</span>分<span id="RemainS">00</span>秒
</span>// JS 代碼<script>var runtimes = 0;function GetRTime(){var nMS = <?=$lefttime?>*1000-runtimes*1000;//var nD = Mach.floor(nMS/(1000*60*60*24)) % 30var nH=Math.floor(nMS/(1000*60*60))%24;var nM=Math.floor(nMS/(1000*60)) % 60;var nS=Math.floor(nMS/1000) % 60;if(nMS>0){$("#RemainH").html(nH)$("#RemainM").html(nM)$("#RemainS").html(nS)}runtimes++;setTimeout("GetRTime()",1000);}window.οnlοad=GetRTime;
</script>
?
轉(zhuǎn)載于:https://www.cnblogs.com/zhanzy/p/6631412.html
總結(jié)
以上是生活随笔為你收集整理的PHP 实现简单的 倒计时 时分秒的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 梦到自己生孩子是什么预兆周公解梦
- 下一篇: 孕妇梦到胎盘是什么意思啊