美文网首页
JS 倒计时倒计时—— 日:时:分:秒

JS 倒计时倒计时—— 日:时:分:秒

作者: 2点半 | 来源:发表于2018-11-07 01:07 被阅读0次
    TimeDown (t) {
                 t= t.replace(/\-/g,"/");
                var now = new Date();
                var endDate = new Date(t);
                var n=(endDate.getTime()-now.getTime())/1000;
                var days=0,
                    hours=0,
                    minutes=0,
                    seconds=0;
                if(n>=0){
                    days = Math.floor(n  / 3600 /24);
                    hours = Math.floor(n / 3600 % 24);
                    minutes = Math.floor(n / 60 % 60);
                    seconds = Math.floor(n % 60);
                }
                if(days <= 9) days ='0'+days;
                if(hours <= 9) hours ='0'+hours;
                if(minutes <= 9) minutes ='0'+minutes;
                if(seconds <= 9) seconds = '0'+seconds;
                var resultTime =[days,hours,minutes,seconds];
                this.resultTime =resultTime;

            },

相关文章

网友评论

      本文标题:JS 倒计时倒计时—— 日:时:分:秒

      本文链接:https://www.haomeiwen.com/subject/dkfmxqtx.html