js天数倒计时

来源:互联网 发布:淘宝刷买家秀平台 编辑:程序博客网 时间:2024/06/05 18:35
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<title>倒计时</title>
</head>
<body>
<div id="times"></div>
<script type="text/javascript">
    function _fresh()
    {
        var endtime=new Date("Mar 31, 2014 18:00:00");//这里设置预制时间
        var nowtime = new Date();
        var leftsecond=parseInt((endtime.getTime()-nowtime.getTime())/1000);
        if(leftsecond<0){leftsecond=0;}
        __d=parseInt(leftsecond/3600/24);
        __h=parseInt((leftsecond/3600)%24);
        __m=parseInt((leftsecond/60)%60);
        __s=parseInt(leftsecond%60);
        document.getElementById("times").innerHTML=__d+"天 "+__h+"小时"+__m+"分"+__s+"秒";
    }
    _fresh()
    setInterval(_fresh,1000);
</script>
</body>
</html>
0 0
原创粉丝点击