首页 资讯 论坛 我的社区 搜索 用户

[js]js倒计时

无闻风
发表于 2019-10-14 01:06:23
0
1143

结果输出到<div id="djs"></div>

<div id="djs"></div>
<script type="text/javascript">
window.onload=clock;
function clock()
{
    var today=new Date(),h=today.getHours(),m=today.getMinutes(),s=today.getSeconds();
    var stopTime=new Date("9 22 2021 00:00:00"),stopH=stopTime.getHours(),stopM=stopTime.getMinutes(),stopS=stopTime.getSeconds();
    var shenyu=stopTime.getTime()-today.getTime(),shengyuD=parseInt(shenyu/(60*60*24*1000)),D=parseInt(shenyu)-parseInt(shengyuD*60*60*24*1000),shengyuH=parseInt(D/(60*60*1000)),H=D-shengyuH*60*60*1000,shengyuM=parseInt(H/(60*1000)),M=H-shengyuM*60*1000;
    S=parseInt((shenyu-shengyuD*60*60*24*1000-shengyuH*60*60*1000-shengyuM*60*1000)/1000);
    if(shengyuH<10)
    {
        shengyuH='0'+shengyuH;
    }
    if(shengyuM<10)
    {
        shengyuM='0'+shengyuM;
    }
    if(S<10)
    {
        S='0'+S;
    }
    document.getElementById("djs").innerHTML=(shengyuD+" Days "+shengyuH+":"+shengyuM+":"+S);
    setTimeout(clock,1000);
}
</script>


最后修改 2019-10-14 01:06:23
0
1143
用户评论
一起折腾