参考下面代码:
<script type="text/javascript">
function getRTime(){
var EndTime= new Date('<%=datas%>'); //datas是数据库的时间
var NowTime = new Date();
var t =EndTime.getTime() - NowTime.getTime();
if(t>=0){
var d=Math.floor(t/1000/60/60/24);
var h=Math.floor(t/1000/60/60%24);
var m=Math.floor(t/1000/60%60);
var s=Math.floor(t/1000%60);
document.getElementById("t_d").innerHTML = d;
document.getElementById("t_h").innerHTML = h;
document.getElementById("t_m").innerHTML = m;
document.getElementById("t_s").innerHTML = s;
}
}
setInterval(getRTime,1000);
</script>
温馨提示:内容为网友见解,仅供参考