jsカウントダウン--ある日のカウントダウンと毎晩12時までのカウントダウン

1117 ワード

// var endTime=new Date('2017-3-19'); // 24:0:0 /*var endYear=new Date().getFullYear(); var endMonth=new Date().getMonth()+1; var endDay=new Date().getDate(); var endTime2=new Date(endYear,endMonth,endDay);*/ var leftDiv=function(){ var leftTime=endTime-(new Date().getTime()); var leftHours=addNumber(Math.floor(leftTime/1000/60/60%24)); var leftMinutes=addNumber(Math.floor(leftTime/1000/60%60)); var leftSeconds=addNumber(Math.floor(leftTime/1000%60)); document.getElementById("divTime").innerText=" "+leftHours+" "+leftMinutes+" "+leftSeconds+" "; if(leftTime>0){ setTimeout(function(){ leftDiv(); },500); }else{ clearTimeout(leftDiv()) } } leftDiv(); function addNumber(num){ var num=(num>9)?num:('0'+num); return num; }