js 倒计时

突然想到的

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>js倒计时</title>
    </head>
    <body>
        <div id="newdata"></div>
        <div id="olddata"></div>
    </body>
</html>
<script>
    function show(){
        setInterval(function(){
            var odata = new Date();
            var oyears = odata.getFullYear(); 
            var omonth = odata.getMonth()+1;
            var oday = odata.getDate();
            var ohours = odata.getHours();
            var ominutes = odata.getMinutes();
            var oseconds = odata.getSeconds();
            //时间表
            document.getElementById('newdata').innerHTML = oyears +'-'+ omonth+'-'+oday+'   '+ohours+':'+ominutes+':'+oseconds ;
            //倒计时
            var amonth = 12-omonth; 
//          var arr = new Array();  本来打算把每月的天数存放到数组里
            var days = 0;
            if(omonth == 1||omonth == 3||omonth == 5||omonth == 7||omonth ==8||omonth == 10||omonth == 12){
                days = 31;
            }else if(omonth == 2){
                if(oyears%4 == 0&&oyears%100!=0&&oyears%400==0){ //四年一闰百年不闰四百年又闰
                    days = 29;
                }else{
                    days =28;
                }
            }else{
                days = 30;
            }
            var aday = days-oday;
            var ahours = 24-ohours;
            var amintes = 60-ominutes;
            var aseconds = 60-oseconds;
            document.getElementById('olddata').innerHTML = '倒计时:'+oyears +'年还剩'+ amonth+'个月'+aday+'天'+ahours+'小时'+amintes+'分钟'+aseconds +'秒';

        },1000);

    }
    show();

</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值