js中date倒计时

获取倒计时之前,我们不妨先来看怎样获取当前时间吧!!!

function time(){
            var oDate = new Date();
            var year = oDate.getFullYear();
            var month = oDate.getMonth() + 1     ;
            var dDate = oDate.getDate();
            var day = oDate.getDay();
            var house = oDate.getHours();
            var minu = oDate.getMinutes();
            var sec = oDate.getSeconds();
            
            
            switch(day){
                case 1:
                day = '星期一';
                break;
                case 2:
                day = '星期二';
                break;
                case 3:
                day = '星期三';
                break;
                case 4:
                day = '星期四';
                break;
                case 5:
                day = '星期五';
                break;
                case 6:
                day = '星期六';
                break;
                case 0:
                day = '星期日';
                break;
            }
            
            function double( t ){
                if( t < 10 ){
                    t = '0' + t;
                }
                return t;
            }
            
            
            document.body.innerHTML = year + '年' + month +'月'+ dDate + '日  ' + day + ' ' + double(house) +':'+ double(minu) +':' + double(sec);
        }
        time();
        setInterval(time,1000);

获取倒计时

1、实现倒计时功能
2、倒计时结束按钮可被点击,之前不可被点击

0天 00: 00: 00


#btn{ text-decoration: none; display: block; width: 100px; height: 35px; background: #ccc; text-align: center; line-height: 35px; color: #666; } #btn.btn{ background: red; color: #fff; font-size: 20px; font-weight: bold; } 即将开抢!

效果图如下:

js中date倒计时_第1张图片
Paste_Image.png

你可能感兴趣的:(js中date倒计时)