Try this
https://jsfiddle.net/6bd3L1ew/7/
config = {
'0':8,
'1':7,
'2':6,
'3':5,
'4':4,
'5':3,
'6':2,
'7':1,
'8':1,
'9':1,
'10':1,
'11':1,
'12':1,
'13':1,
'14':1,
'15':1,
'16':1,
'17':15,
'18':14,
'19':13,
'20':12,
'21':11,
'22':10,
'23':9
}
var start = new Date();
function pad(num) {
return ("0" + parseInt(num)).substr(-2);
}
function tick() {
var nowTime = new Date().getHours();
var untilTime = new Date().getHours() + config[nowTime]
start.setHours(untilTime, 0, 0);
var now = new Date();
if (now > start) { // too late, go to tomorrow
start.setDate(start.getDate() + 1);
}
var remain = ((start - now) / 1000);
var hh = pad((remain / 60 / 60) % 60);
var mm = pad((remain / 60) % 60);
var ss = pad(remain % 60);
document.getElementById('time').innerHTML =
hh + ":" + mm + ":" + ss;
setTimeout(tick, 1000);
}
tick();
3
solved Countdown that can mix various times