JS或者PHP的倒计时程序代码
发布网友
发布时间:2022-04-07 13:24
我来回答
共2个回答
热心网友
时间:2022-04-07 14:53
<p class="tips" id="tips"></p>
<p><span class="h" id="h"></span>时</p>
<p><span class="m" id="m"></span>分</p>
<p><span class="s" id="s"></span>秒</p>
<script type="text/javascript">
<!--
setInterval(
function(){
var date = new Date();
hours = date.getHours();
minutes = date.getMinutes();
seconds = date.getSeconds();
if(hours>=0 && hours<10){
document.getElementById('tips').innerHTML = '距离抢购还剩下';
document.getElementById('h').innerHTML = (9-hours);
document.getElementById('m').innerHTML = seconds==0? (60-minutes) : (59-minutes);
document.getElementById('s').innerHTML = seconds==0? 0 : (60-seconds);
}else if(hours>=10 && hours<20){
document.getElementById('tips').innerHTML = '抢购已持续';
document.getElementById('h').innerHTML = (hours-10);
document.getElementById('m').innerHTML = minutes;
document.getElementById('s').innerHTML = seconds;
}else{
document.getElementById('tips').innerHTML = '今日抢购已结束,感谢您的关注。';
document.getElementById('h').innerHTML = '';
document.getElementById('m').innerHTML = '';
document.getElementById('s').innerHTML = '';
}
},
1000);
-->
</script>追问请教下,如何让小于10的数字前多个0,例如 6:8:20 显示为 06:08:20
追答
时
分
秒
=0 && hours=10 && hours10? c : '0'+c;
}
-->
热心网友
时间:2022-04-07 16:11
用Date函数,以格式化方式获得php服务器的时间,然后与设定的时间做减法,即可写出,参阅
http://www.w3school.com.cn/php/php_ref_date.asp