<script type="text/javascript"> var serverTime = <?php echo time();?> * 1000; var gotobuy=0,gotopay=0; var timeout=null; $(function(){ var dateTime = new Date(); var difference = dateTime.getTime() - serverTime; timeout = setInterval(function(){ $(".endtime").each(function(){ var obj = $(this); var endTime = new Date(parseInt(obj.attr('value')) * 1000); var nowTime = new Date(); var nMS=endTime.getTime() - nowTime.getTime() + difference; var myD=Math.floor(nMS/(1000 * 60 * 60 * 24)); //天 var myH=Math.floor(nMS/(1000*60*60)) % 24; //小时 var myM=Math.floor(nMS/(1000*60)) % 60; //分钟 var myS=Math.floor(nMS/1000) % 60; //秒 var myMS=Math.floor(nMS/100) % 10; //拆分秒 if(myD>= 0){ var str = (myD>0?'<span>'+myD+'</span>天':'')+'<span>'+myH+'</span>小时<span>'+myM+'</span>分<span>'+myS+'</span>秒<span>'+myMS+'</span>'; //显示倒计时 }else{
//倒计时结束 window.clearInterval(timeout); var str = '<span>0</span>小时<span>0</span>分<span>0</span>秒'; } obj.html(str); }); }, 100); }); </script>