1)、PHP部分:
2)、JS部分:
<script language="javascript"> var serverTime = * 1000; $(function(){ var dateTime = new Date(); var difference = dateTime.getTime() - serverTime; 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 = myM+"分"+myS+"秒"; }else{ var str = "已结束!"; } obj.html(str); }); }, 100); }); </script>
3、HTML部分:
<div class="endtime" value="{dede:php}echo $endTime;{/dede:php}"></div>