Javascript countdown to 6pm.

My working hours were recently changed to a more accommodating  schedule in which I now leave at 6pm as opposed to 11pm before. As a result I modified my Javascript countdown script to reflect my new departure time and while I was at it I changed the format to appear as a clock showing the hours and minutes remaining until 6pm. While I was at it I worked in a border around the numbers to make it look nice and pretty, like this:

1020

That means as I type this post, there are 10 hours and 20 minutes until 6pm.

Here’s the modified script.

<html>
<head>
<title>Countdown Clock</title>
</head>
<body>
<script type=”text/javascript”>
// From: http://www.webdeveloper.com/forum/showthread.php?t=215504
// Modified for: http://www.webdeveloper.com/forum/showthread.php?t=220174
var definedTime = new Date(’23:00′); // military time to countdown TO
function ShowTimes() {
var now = new Date();
var hrs = 17-now.getHours();
if (hrs < 0) { hrs += 24; }
var mins = 60-now.getMinutes();
var secs = 60-now.getSeconds();
var str = ”;
str += ‘<center><table border=”5″><tr><td><p style=”font-size:xx-large;”>’+hrs+’:’+mins+'</p></td></tr></table></center>’;
document.getElementById(‘countdownToMidnight’).innerHTML = str;
}

var _cntDown;
function StopTimes() { clearInterval(_cntDown); }
</script>
</head>
<body onload=”_cntDown=setInterval(‘ShowTimes()’,1000)”>
<div id=”countdownToMidnight”></div>
</body>
</html>

If you want the countdown clock to count down to 5pm instead, you would change the 17 (highlighted in red) to 16.

Advertisements

Tags: ,

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: