<div class="time">
<span class="day"></span>
<i>天</i>
<span class="hour"></span>
<i>时</i>
<span class="minute"></span>
<i>分</i>
<span class="second"></span>
<i>秒</i>
</div>
function countDown(time,day_elem,hour_elem,minute_elem,second_elem){
//if(typeof end_time == "string")
var end_time = new Date(time).getTime(),//月份是实际月份-1
//current_time = new Date().getTime(),
sys_second = (end_time-new Date().getTime())/1000;
var timer = setInterval(function(){
if (sys_second > 0) {
sys_second -= 1;
var day = Math.floor((sys_second / 3600) / 24);
var hour = Math.floor((sys_second / 3600) % 24);
var minute = Math.floor((sys_second / 60) % 60);
var second = Math.floor(sys_second % 60);
day_elem && $(day_elem).text(day<10?"0"+day:day);//计算天
$(hour_elem).text(hour<10?"0"+hour:hour);//计算小时
$(minute_elem).text(minute<10?"0"+minute:minute);//计算分
$(second_elem).text(second<10?"0"+second:second);// 计算秒
} else {
clearInterval(timer);
}
}, 1000);
}
function timer2(time_group){
var i,time_on,
time_num = time_group.length,
current_time_year = new Date().getFullYear().toString(),
current_time_month = ((new Date().getMonth()+1)<10?"0"+(new Date().getMonth()+1):(new Date().getMonth()+1)).toString(),
current_time_day = (new Date().getDate()<10?"0"+new Date().getDate():new Date().getDate()).toString(),
current_time_hours = (new Date().getHours()+1).toString(),
current_time_minute = new Date().getMinutes().toString(),
current_time_second = new Date().getSeconds().toString(),
current_time = current_time_year + "/" + current_time_month + "/" + current_time_day + " " + current_time_hours + ":" + current_time_minute + ":" + current_time_second;
for(i=0;i<time_num;i++){
if(time_group[i] > current_time){
time_on = time_group[i];
countDown( time_on, ".time .day", ".time .hour", ".time .minute", ".time .second" );
break;
}
}
}
// 时间数组,可输入多个时间节点,时间节点过期后js会自动切换至下个时间节点
var time_group = new Array("2015/08/30 00:00:00","2015/09/05 00:00:00","2015/09/12 00:00:00","2015/09/13 00:00:00","2015/09/19 00:00:00","2015/10/10 00:00:00","2015/10/11 00:00:00","2015/10/24 00:00:00","2015/10/25 00:00:00","2015/10/31 00:00:00","2015/11/08 00:00:00","2015/11/14 00:00:00","2015/11/15 00:00:00","2015/11/21 00:00:00","2015/11/28 00:00:00","2015/11/29 00:00:00","2015/12/05 00:00:00","2015/12/12 00:00:00","2015/12/13 00:00:00","2015/12/19 00:00:00","2015/12/20 00:00:00");
timer2(time_group);