Created
December 23, 2013 05:34
-
-
Save 64lines/8092131 to your computer and use it in GitHub Desktop.
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
<html> | |
<body> | |
<h1 id="title">The Chronos Meter</h1> | |
<script language="javascript"> | |
var divChronometer = document.createElement("div"); | |
divChronometer.id = "chronometer"; | |
document.body.appendChild(divChronometer); | |
startChronometer(); | |
function startChronometer() { | |
var miliseconds = 0; | |
var seconds = 0; | |
var minutes = 0; | |
var hours = 0; | |
var timer = setInterval(function() { | |
var format = ""; | |
format += (hours < 10 ? "0" + hours : hours) + ":"; | |
format += (minutes < 10 ? "0" + minutes : minutes) + ":"; | |
format += (seconds < 10 ? "0" + seconds : seconds) + ":"; | |
format += miliseconds; | |
divChronometer.innerHTML = format; | |
if (miliseconds == 100) { | |
miliseconds = 0; | |
if (seconds == 60) { | |
seconds = 0; | |
if(minutes == 60) { | |
minutes = 0; | |
if(hours == 60) { | |
hours = 0; | |
} | |
hours++; | |
} | |
minutes++; | |
} | |
seconds++; | |
} | |
miliseconds++; | |
}, 1); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment