js 倒计时 已过去时间
页面中的代码:
<strong id="timer" datatime="2012-12-09 10:20:30"></strong>
<script>
//获取申请时间
var time_now_server;
//开始时间
var time_now_server=$("#timer").attr("datatime");
time_now_server = time_now_server*1000;
setTimeout("show_time()",1000);
</script>
JS的代码
//倒计时js 已过去时间
function show_time(){
var timer = document.getElementById("timer");
if(!timer){
return ;
}
var time_now,time_distance,str_time;
var int_day,int_hour,int_minute,int_second;
var time_now=new Date();
time_now=time_now.getTime();
time_distance=time_now-time_now_server;
if(time_distance>0)
{
int_day=Math.floor(time_distance/86400000)
time_distance-=int_day*86400000;
int_hour=Math.floor(time_distance/3600000)
time_distance-=int_hour*3600000;
int_minute=Math.floor(time_distance/60000)
time_distance-=int_minute*60000;
int_second=Math.floor(time_distance/1000)
// if(int_hour<10)
// int_hour="0"+int_hour;
// if(int_minute<10)
// int_minute="0"+int_minute;
if(int_second<10)
int_second="0"+int_second;
str_time=int_day+"天"+int_hour+"小时"+int_minute+"分钟"+int_second+"秒";
timer.innerHTML=str_time;
setTimeout("show_time()",1000);
}
else
{
timer.innerHTML =timer.innerHTML;
clearTimeout(timer)
}
}