php js倒计时代码(倒计时代码
发布日期:2021-05-04 09:21:33 浏览次数:40 分类:原创文章

本文共 6290 字,大约阅读时间需要 20 分钟。

刷新网页继续会倒计

<?php    //php的时间是以秒算。js的时间以毫秒算    date_default_timezone_set('PRC');    //date_default_timezone_set("Asia/Hong_Kong");//地区     $timestr = "2017-3-21 18:50:00";//倒计时时间    $time = strtotime($timestr);//时间戳    $nowtime = time();//当前时间戳     if ($time>=$nowtime){        $overtime = $time-$nowtime; //实际剩下的时间(单位/秒)    }else{        $overtime=0;    }?><!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title></head><body><script language="JavaScript">    var runtimes = 0;    function GetRTime(){        var nMS = <?php echo $overtime; ?>*1000-runtimes*1000;         if (nMS>=0){            var nD=Math.floor(nMS/(1000*60*60*24))%24;            var nH=Math.floor(nMS/(1000*60*60))%24;            var nM=Math.floor(nMS/(1000*60)) % 60;            var nS=Math.floor(nMS/1000) % 60;            document.getElementById("RemainD").innerHTML=nD;            document.getElementById("RemainH").innerHTML=nH;            document.getElementById("RemainM").innerHTML=nM;            document.getElementById("RemainS").innerHTML=nS;            runtimes++;            if(nD==0){                //天数0 隐藏天数                document.getElementById("hideD").style.display="none";                if(nH==0){                    //数0 隐藏天数                    document.getElementById("hideH").style.display="none";                    if(nM==0){                        document.getElementById("hideM").style.display="none";                        if(nS==0){                            alert("倒计时完毕");                        }                    }                }            }            setTimeout("GetRTime()",1000);        }    }    window.onload = function() {        GetRTime();    }</script><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></body></html> 



完整例子:在某个时间上增加X分钟,倒计时 ,到时间后自动提交表单

这些元素到这里找:http://www.layui.com/

<link href="../templates/metx5/layui/css/layui.css" rel="stylesheet">
<script src="../templates/metx5/layui/lay/dest/layui.all.js"></script>

<?php    //php的时间是以秒算。js的时间以毫秒算    date_default_timezone_set('PRC');    //date_default_timezone_set("Asia/Hong_Kong");//地区$start_time="2017-3-22 17:00:00";//开始考试时间echo $start_time."<br>";	$mm=120*60;//分钟换成钞钟 考试时间$min=date("Y-m-d H:i:s",strtotime($start_time)+$mm);//$start_time 用户开始考试时的时间//$min=date($start_time,strtotime("+$mm minute"));//$start_time 用户开始考试时的时间echo $min."<br>";	 	 	 $timestr=$min;//倒计时时间    //$timestr = "2017-3-22 12:50:00";    $time = strtotime($timestr);//时间戳    $nowtime = time();//当前时间戳     if ($time>=$nowtime){        $overtime = $time-$nowtime; //实际剩下的时间(单位/秒)		$start_ok=0;//考试时间未结束时 设定$start_ok=0    }else{        $overtime=0;		$start_ok=1;//考试时间结束 设定$start_ok=1    }//echo date('Y-m-d H:i:s',strtotime("+120 minute"));?><!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title><script type="text/javascript" src="http://libs.baidu.com/jquery/1.8.3/jquery.js"></script><link href="../templates/metx5/layui/css/layui.css" rel="stylesheet"><script src="../templates/metx5/layui/lay/dest/layui.all.js"></script><style>	.layui-layer-demo .layui-layer-title {    border: none;    background-color: #E60012;    color: #fff;}.layui-layer-title {    padding: 0 80px 0 20px;    height: 42px;    line-height: 42px;    border-bottom: 1px solid #eee;    font-size: 14px;    color: #333;    overflow: hidden;    background-color: #F8F8F8;    border-radius: 2px 2px 0 0;}	.layui-layer-page .layui-layer-content {    position: relative;    overflow: auto;}.layui-layer-content {    position: relative;}	</style></head><body><form name="form1" action="index.php"> </form> <script language="JavaScript">    var runtimes = 0;    function GetRTime(){        var nMS = <?php echo $overtime; ?>*1000-runtimes*1000;         if (nMS>=0){            var nD=Math.floor(nMS/(1000*60*60*24))%24;            var nH=Math.floor(nMS/(1000*60*60))%24;            var nM=Math.floor(nMS/(1000*60)) % 60;            var nS=Math.floor(nMS/1000) % 60;            document.getElementById("RemainD").innerHTML=nD;            document.getElementById("RemainH").innerHTML=nH;            document.getElementById("RemainM").innerHTML=nM;            document.getElementById("RemainS").innerHTML=nS;            runtimes++;            if(nD==0){                //天数0 隐藏天数                document.getElementById("hideD").style.display="none";                if(nH==0){                    //数0 隐藏天数                    document.getElementById("hideH").style.display="none";                    if(nM==0){                        document.getElementById("hideM").style.display="none";                        if(nS==0){							layer.open({							  type: 1,							  skin: 'layui-layer-demo', //样式类名							  shade: [0.5, '#000'],//遮罩 即弹层外区域 							  closeBtn: 0, //不显示关闭按钮							  anim: 2,							  time: 900000,//即代表3秒后自动关闭,注意单位是毫秒(1秒=1000毫秒) 默认0不会自动关闭							  shadeClose: false, //开启遮罩关闭							  content: '<div id="" class="layui-layer-content"><div style="padding:20px;">考试时间已经结束!<br>你怎么样给她整容都行<br><br><br>我是华丽的酱油==。</div></div>'							});							//$start_ok=2;//							setInterval("document.all.form1.submit()",5000)//5秒后自动提交表单form1//  layer.msg('考试时间已经结束!', {//	 shade: [0.5, '#000'],//遮罩 即弹层外区域 //    time: 2000, //20s后自动关闭//    btn: ['立即提交', '知道了']//  ,yes: function(index, layero){//    //按钮【按钮一】的回调//	  self.location='index.php?#top';//立即投资按钮//  }//  ,btn2: function(index, layero){//    //按钮【按钮二】的回调//    //self.location='index1.php?#top';//立即投资按钮//    //return false 开启该代码可禁止点击该按钮关闭//  }//  });							//setTimeout('window.location="http://panliu888.myetang.com"',9000)                        }                    }                }            }            setTimeout("GetRTime()",1000);        }    }    window.onload = function() {        GetRTime();    }</script><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><?php echo $start_ok?></body></html> 






引用:http://www.cnblogs.com/whowhere/archive/2016/11/14/6062002.html

上一篇:PHP的时间增加10分钟和加一天的时间
下一篇:JS倒计时代码(可随时点击停止)

发表评论

最新留言

表示我来过!
[***.240.166.169]2025年03月22日 07时49分56秒