Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pad(n, len) { // leading 0's
- var s = n.toString();
- return (new Array( (len - s.length + 1) ).join('0')) + s;
- };
- function countDown() {
- var now = new Date();
- var targetDay = 4; // Thursday (4) is the target day
- var target = 0; // Hour of the day to cutoff (0 for midnight)
- var days = 0, hrs = 0, mins = 0, secs = 0;
- //--> Day logic
- if(now.getDay() < targetDay - 1) {
- days = targetDay - now.getDay() - 1;
- }
- else if(now.getDay() > targetDay) {
- days = 8 - now.getDay() + targetDay;
- }
- //<-- Day logic
- // Countdown logic
- if (now.getHours() < target) {
- hrs = (target - 1) - now.getHours();
- if (hrs < 0) hrs = 0;
- mins = 59 - now.getMinutes();
- if (mins < 0) mins = 0;
- secs = 59 - now.getSeconds();
- if (secs < 0) secs = 0;
- }
- else if (now.getHours() > target) {
- hrs = 24 - now.getHours() + (target - 1);
- if (hrs < 0) hrs = 0;
- mins = 59 - now.getMinutes();
- if (mins < 0) mins = 0;
- secs = 59 - now.getSeconds();
- if (secs < 0) secs = 0;
- }
- else { // It's time!
- document.getElementById('countdownTimer').innerHTML = "It's time!";
- }
- }
- // Run immediately to get rid of delay
- countDown();
- // Run every second to update time remaining
- if (document.getElementById('countdownTimer')) {
- var timerRunning = setInterval(
- function() {
- countDown();
- }, 1000
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement