(function(){
function getDate(endTime){
var future = new Date(endTime);
var now = new Date();
if(now > future){
return;
}
var leftSecond = (future.getTime() - now.getTime())/1000;
var day = parseInt(leftSecond/(24*60*60));
var hour = parseInt((leftSecond/3600)%24);
var min = parseInt((leftSecond/60)%60);
var sec = parseInt(leftSecond%60);
if(day < 10){
day = "0"+day;
}
if(hour < 10){
hour = "0"+hour;
}
if(min < 10){
min = "0"+min;
}
if(sec < 10){
sec = "0"+sec;
}
if(day == 0 && hour == 0 && min == 0 && sec == 0){
clearInterval(TimeId);
}
document.getElementById("date").innerHTML = day;
document.getElementById("time").innerHTML = hour + ":" + min + ":" + sec;
console.log(day+"天"+hour+"小时"+min+"分"+sec+"秒");
}
var TimeId = setInterval(function(){
//这个函数接收结束日期
getDate('2014/07/20 10:40:20');
},1000);
})();