Skip to content

Instantly share code, notes, and snippets.

@dknight
Created June 22, 2010 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dknight/448074 to your computer and use it in GitHub Desktop.
Save dknight/448074 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Prototype JS - My template for tutorials</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
</head>
<body>
<span id="hours"></span> :
<span id="minutes"></span> :
<span id="seconds"></span>
<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[
// For month use MONTH - 1
var deadline = new Date(2010, 6, 22, 0, 0, 0, 0);
var hours = minutes = seconds = 0;
//start first time without delay
timer();
//Run the loop interval
setInterval("timer()", 1000);
function timer()
{
var now = new Date();
var diff = Math.round((deadline - now) / 1000); // get rid of miliseconds
if( diff > 0) {
hours = diff / (60 * 60);
minutes = (hours - Math.floor(hours)) * 60;
seconds = (minutes - Math.floor(minutes)) * 60;
hours = (hours < 10) ? '0' + Math.floor(hours) : Math.floor(hours);
minutes = (minutes < 10) ? '0' + Math.floor(minutes) : Math.floor(minutes);
seconds = (seconds < 10) ? '0' + Math.floor(seconds) : Math.floor(seconds);
} else {
hours = minutes = seconds = '00'; // Is this ass? :-)
}
document.getElementById('hours').innerHTML = hours;
document.getElementById('minutes').innerHTML = minutes;
document.getElementById('seconds').innerHTML = seconds;
}
// ]]>
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment