我有一些每日倒數計時器的代碼,每天計數到中午12點。我想排除我已經這樣做週末:只在特定日期後運行javascript功能
if((t.total<=0) || (day === 0) || (day === 6)){
clearInterval(timeinterval);
document.getElementById('deadline_Container').style.display = "none";
}
}
不過,我還需要一定時間做到這一點,使倒計時不會20.12之間顯示。到27.12。例如。不知道如何在特定的日期做到這一點?
這是我的全部代碼:
<script type="text/javascript">
var today = new Date(new Date().getTime());
var deadline = new Date(Date.UTC(today.getFullYear(),today.getMonth(), today.getDate(), 11, 59, 59));
function time_remaining(endtime){
var t = endtime - new Date();
var seconds = Math.floor((t/1000) % 60);
var minutes = Math.floor((t/1000/60) % 60);
var hours = Math.floor((t/(1000*60*60)) % 24);
return {'total':t, 'hours':hours, 'minutes':minutes, 'seconds':seconds};
}
function run_clock(id,endtime){
var clock = document.getElementById(id);
if (null === clock) {
return;
}
var hours_span = clock.querySelector('.hours');
var minutes_span = clock.querySelector('.minutes');
var seconds_span = clock.querySelector('.seconds');
function update_clock(){
var t = time_remaining(endtime);
hours_span.innerHTML = ('0' + t.hours).slice(-2);
minutes_span.innerHTML = ('0' + t.minutes).slice(-2);
seconds_span.innerHTML = ('0' + t.seconds).slice(-2);
day = today.getDay();
if((t.total<=0) || (day === 0) || (day === 6)){
clearInterval(timeinterval);
document.getElementById('deadline_Container').style.display = "none";
}
}
update_clock();
var timeinterval = setInterval(update_clock,1000);
}
run_clock('clockdiv',deadline);
</script>
<div id="deadline_Container">
<div id="clockdiv">
<!-- <div><span class="days"></span><span class="smalltext">Days</span></div> -->
<div><span class="hours"></span><span class="smalltext">Hours</span></div>
<div><span class="minutes"></span><span class="smalltext">Minutes</span></div>
<div class="clockLast"><span class="seconds"></span><span class="smalltext">Seconds</span></div>
</div>
</div>