页面倒计时

来源:互联网 发布:apache shiro文档 编辑:程序博客网 时间:2024/04/29 16:57
<%
    //秒杀倒计时
    String sDt = "05/27/2013 21:00:00";
    SimpleDateFormat sdf=  new  SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    Date dt2 = sdf.parse(sDt);
    long beginTime = dt2.getTime();

%>

<script language="javascript">
setTimeout("show_time()",1000);
function show_time()
{
    var 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=timeForm.time_begin.value-time_now;
    //时间间隔。timeForm.time_end.value是竞拍商品的到期时间
    if(time_distance>0)
    {
       //取出间隔时间的天、小时、分,java中时间换成毫秒是按照1000*60*60*24这样的换算方式转的
       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+"天<br>"+int_hour+":"+int_minute+":"+int_second;
       hour.innerHTML=int_hour;
       minute.innerHTML=int_minute;
       second.innerHTML=int_second;
       timer.innerHTML=str_time;
       setTimeout("show_time()",1000);  //循环调用
     }else
     {
       timer.innerHTML ="over";
       clearTimeout(timerID)
     }
}
</script>

<form name="timeForm">
                    <input type="hidden" name="time_begin" value="<%=beginTime %>" />
                    
                     <tr>  
                        <td>
                              <div align="center">剩余时间</div>
                        </td>
                            <td class="time">
                              <div id="timer"></div>
                        </td>
                      </tr>
</form>
原创粉丝点击