-
-
Save asantos071/6fdd7e5a34b9f68ba41f559e9eab19f4 to your computer and use it in GitHub Desktop.
[JAVASCRIPT] Timer with javascript.
This file contains 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
<script> | |
function pretty_time_string(num) { | |
return ( num < 10 ? "0" : "" ) + num; | |
} | |
var start = new Date; | |
setInterval(function() { | |
var total_seconds = (new Date - start) / 1000; | |
var hours = Math.floor(total_seconds / 3600); | |
total_seconds = total_seconds % 3600; | |
var minutes = Math.floor(total_seconds / 60); | |
total_seconds = total_seconds % 60; | |
var seconds = Math.floor(total_seconds); | |
hours = pretty_time_string(hours); | |
minutes = pretty_time_string(minutes); | |
seconds = pretty_time_string(seconds); | |
var currentTimeString = hours + ":" + minutes + ":" + seconds; | |
$('.timer').text(currentTimeString); //jQuery needed | |
}, 1000); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment