var airDate = Date.UTC(2017, 8-1, 12, 15, 30, 0); // Year, month-1, day, hour, minute, second (UTC) var week = 7*24*60*60*1000; var counttimes = 12; // How many weeks to count down var count_finish = "Countdown is currently out of service."; // Message displayed when countdown ends var count_redir = null; // Website to redirect to when countdown finished, null if no redirect function zf(v) { return ""+v; } function readableTime(timems, ignoreMs) { var time = timems|0; var ms = ignoreMs?'':"."+zf((timems*100)%100|0); if (time < 60) return ""+zf(time)+ms+" Second"+(zf(time)+ms==1?"":"s")+""; else if (time < 3600) return ""+zf(time / 60|0)+" Minute"+(zf(time / 60|0) == 1?"":"s")+" "+zf(time % 60)+ms+" Second"+(zf(time % 60)+ms==1?"":"s")+""; else if (time < 86400) return ""+zf(time / 3600|0)+" Hour"+(zf(time / 3600|0)==1 ? "" : "s")+" "+zf((time % 3600)/60|0)+" Minute"+(zf((time % 3600)/60|0)==1 ? "" : "s")+" "+zf((time % 3600)%60)+ms+" Second"+(zf((time % 3600)%60)+ms==1?"":"s")+""; else return ""+(time / 86400|0)+" Day"+((time / 86400|0)==1?"":"s")+" "+zf((time % 86400)/3600|0)+" Hour"+(zf((time % 86400)/3600|0) == 1 ? "" : "s")+" "+zf((time % 3600)/60|0)+" Minute"+(zf((time % 3600)/60|0)==1?"":"s")+" "+zf((time % 3600)%60)+" Second"+(zf((time % 3600)%60)==1?"":"s")+""; } function get() { var counter = 0; var now = Date.now(); var cdclock = document.getElementById("cdcontainer"); //return cdclock.innerHTML = "Hiatus! Check back in a month or two!"; do { var timeLeft = Math.max(((airDate+week*(counter++)) - now)/1000, 0); } while (timeLeft === 0 && counter < counttimes); if (timeLeft === 0) { if(count_redir != null) { location.href = count_redir; } cdclock.innerHTML = ""+count_finish+""; } else { if (airDate/1000 < now/1000 && (now - (airDate + week*(counter-2)))/1000 < 1800) { cdclock.innerHTML = "LIVE NOW"; } else { cdclock.innerHTML = readableTime(timeLeft, true); } } } setInterval((function() {get(); }), 1000);