Countdown v2

ship countdown timer

by Bill Larkin

HTML

<div id="countdownTimer"></div>

CSS

#countdownTimer {padding:20px 10px 20px 10px; background-color:#afc8c5}

JavaScript

// JavaScript Document
if (document.getElementById('countdownTimer')) {
pad = function(n, len) { // leading 0's
var s = n.toString();
return (new Array( (len - s.length + 1) ).join('0')) + s;
};
 
var timerRunning = setInterval(
function countDown() {
var now = new Date();
if ( (now.getDay() >= 1) && (now.getDay() <= 5) ) { // Monday to Friday only
var target = 15; // 15:00hrs is the cut-off point -------- Trying to get 6pm EST regardless of user time zone
if (now.getHours() < target) { // would be best if could hide the whole counter if past cutoff point each day
var hrs = (target - 1) - now.getHours();
//if (hrs < 0) hrs = 0;
if (hrs = 0) '';
var mins = 59 - now.getMinutes();
if (mins < 0) mins = 0;
var secs = 59 - now.getSeconds();
if (secs < 0) secs = 0;
var str = 'Order in the next <strong>' + hrs + ':' + pad(mins, 2) + ':' + pad(secs, 2) + '</strong> to ship <strong>today</strong>.' ;
document.getElementById('countdownTimer').innerHTML = str;
}
}
}, 1000
);
}