倒计时

 1     function ShowCountDown(year,month,day,hours,mintes,seconds,divname) {
 2         function c(xx) {
 3             if(xx<0){
 4                 return 0
 5             }else{
 6                 return (xx<10)?'0'+xx:xx;
 7             }
 8         }
 9         var now = new Date();
10         var endDate = new Date(year, month-1, day,hours,mintes,seconds);
11         var leftTime=endDate.getTime()-now.getTime();
12         var leftsecond = parseInt(leftTime/1000);
13 //var day1=parseInt(leftsecond/(24*60*60*6));
14         var day1=Math.floor(leftsecond/(60*60*24));
15         var hour=Math.floor((leftsecond-day1*24*60*60)/3600);
16         var minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60);
17         var second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60);
18         var cc = document.getElementById(divname);
19         function f(day1,time) {/*负数时间*/
20                 if(day1<0){
21                     return 0
22                 }else{
23                     return (time<10)?'0'+time:time;
24                 }
25         }
26         cc.innerHTML = '<p class="day">'+c(day1)+'天</p>'+'<p class="time">'+f(day1,hour)+"小时"+f(day1,minute)+"分"+f(day1,second)+"秒"+'</p>';
27     }

//调用

var interval = 1000;
    window.setInterval(function(){ShowCountDown(2018,1,15,17,00,00,'time1');}, interval);

 

posted @ 2017-11-16 09:22  =DLSS=webZT  阅读(221)  评论(0编辑  收藏  举报