分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

php倒计时代码编写详细步骤

发布时间:2023-09-06 01:17责任编辑:傅花花关键词:暂无标签
    1. <?php  
    2.     //php的时间是以秒算。js的时间以毫秒算  
    3.     date_default_timezone_set(‘PRC‘);  
    4.     //date_default_timezone_set("Asia/Hong_Kong");//地区  
    5.    
    6.     $timestr = "2017-3-21 18:50:00";//倒计时时间  
    7.     $time = strtotime($timestr);//时间戳  
    8.     $nowtime = time();//当前时间戳  
    9.    
    10.     if ($time>=$nowtime){  
    11.         $overtime = $time-$nowtime; //实际剩下的时间(单位/秒)  
    12.     }else{  
    13.         $overtime=0;  
    14.     }  
    15. ?>  
    16. <!DOCTYPE html>  
    17. <html lang="en">  
    18. <head>  
    19.     <meta charset="UTF-8">  
    20.     <title>Document</title>  
    21.   
    22. </head>  
    23. <body>  
    24.   
    25. <script language="JavaScript">  
    26.     var runtimes = 0;  
    27.     function GetRTime(){  
    28.         var nMS = <?php echo $overtime; ?>*1000-runtimes*1000;  
    29.    
    30.         if (nMS>=0){  
    31.             var nD=Math.floor(nMS/(1000*60*60*24))%24;  
    32.             var nH=Math.floor(nMS/(1000*60*60))%24;  
    33.             var nM=Math.floor(nMS/(1000*60)) % 60;  
    34.             var nS=Math.floor(nMS/1000) % 60;  
    35.             document.getElementById("RemainD").innerHTML=nD;  
    36.             document.getElementById("RemainH").innerHTML=nH;  
    37.             document.getElementById("RemainM").innerHTML=nM;  
    38.             document.getElementById("RemainS").innerHTML=nS;  
    39.             runtimes++;  
    40.             if(nD==0){  
    41.                 //天数0 隐藏天数  
    42.                 document.getElementById("hideD").style.display="none";  
    43.                 if(nH==0){  
    44.                     //数0 隐藏天数  
    45.                     document.getElementById("hideH").style.display="none";  
    46.                     if(nM==0){  
    47.                         document.getElementById("hideM").style.display="none";  
    48.                         if(nS==0){  
    49.                             alert("倒计时完毕");  
    50.                         }  
    51.                     }  
    52.                 }  
    53.             }  
    54.             setTimeout("GetRTime()",1000);  
    55.         }  
    56.     }  
    57.     window.onload = function() {  
    58.         GetRTime();  
    59.     }  
    60. </script>  
    61. <h4>开售还有 <span id="hideD"><strong id="RemainD"></strong>天</span> <span id="hideH"><strong id="RemainH"></strong>小时</span><span id="hideM"> <strong id="RemainM"></strong>分钟</span> <span id="hideS"><strong id="RemainS"></strong>秒</span></h4>  
    62. </body>  
    63. </html> 

php倒计时代码编写详细步骤

原文地址:http://www.cnblogs.com/kewem98898/p/7667385.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved