欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jsp中实现倒计时的代码教程

程序员文章站 2022-07-05 23:24:52
jsp:
还有10天<...

jsp

<section>还有<b class="day" id="d">10</b>天<b class="hour" id="h">5</b>小时<b class="minute" id="m">5</b>分<b class="second" id="s">5</b>秒</section>  
  
<script type="text/javascript">  
    $(document).ready(xc);  
    function xc(){  
            var js_date=${starttime }; //结束时间 可以从数据库中读出来  
        var now_date=new Date().getTime();   
        xc_day=parseInt((js_date-now_date)/1000/60/60/24);  
        xc_h=parseInt((js_date-now_date)/1000/60/60-24*xc_day);  
        xc_m=parseInt((js_date-now_date)/1000/60-xc_day*24*60-xc_h*60);  
        xc_s=parseInt((js_date-now_date)/1000-xc_m*60-xc_h*60*60-xc_day*24*60*60);  
        document.getElementById("d").innerHTML=xc_day;  
        document.getElementById("h").innerHTML=xc_h;  
        document.getElementById("m").innerHTML=xc_m;  
        document.getElementById("s").innerHTML=xc_s;  
        setTimeout("xc()",1000);  
        }  
</script>  

java:

Long starttime = selectionCycle.getStart_time().getTime();  
ServletActionContext.getRequest().setAttribute("starttime ",starttime );