Last active
January 7, 2019 10:45
-
-
Save PerpetualBeta/3964527 to your computer and use it in GitHub Desktop.
A real-time countdown timer for a web page. Will countdown to a target time, but only on days specified (eg: Mon-Fri).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
if (now.getHours() < target) { // don't do anything if we're past the cut-off point | |
var hrs = (target - 1) - now.getHours(); | |
if (hrs < 0) hrs = 0; | |
var mins = 59 - now.getMinutes(); | |
if (mins < 0) mins = 0; | |
var secs = 59 - now.getSeconds(); | |
if (secs < 0) secs = 0; | |
var str = pad(hrs, 2) + ':' + pad(mins, 2) + '.<small>' + pad(secs, 2) + '</small>'; | |
document.getElementById('countdownTimer').innerHTML = str; | |
} | |
} | |
}, 1000 | |
); | |
} |
Those having problems with the plugin not working resulting in '00:00:00'. I have found that when i place the code inside my header it doesn't seem to work. I have moved the piece of code to my footer just before the footer tag and its now working.
< script type="text/javascript" src="daySensitiveCountdownTimer.js"></script>
< footer>
content
< /footer>
Unfortunately it doesn't work for me. No matter where I place the code.
anyway of getting this to use server time? or a specific timezone actually... like EST
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am trying to use this also and it's not working. All I get is 00:00:00 for the countdown timer no matter what time of day it is.