Trying to build a daily "order by" countdown until daily shipping cutoff time. (prefer to keep vanilla js) - on this particular application, server side scripting is not an option.
1: I'm trying to ensure how to set the time to a specific EST time (6pm daily) and not sure if that's possible with vanilla JS?
2: when the timer is counting down and get under an hour left, it reads like 0:mm:ss - is it possible to just hide the hour when it's 0 and only show the mm:ss?
FIDDLE: http://jsfiddle.net/bill9000/rwet0o5f/96/
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
);
}