/ Published in: jQuery
Expand |
Embed | Plain Text
var currentHours = 0; var currentMinutes = 0; var currentSeconds = 0; currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes; currentHours = ( currentHours < 10 ? "0" : "" ) + currentHours; function updateClock ( ) { currentSeconds++; if(currentSeconds >59) { currentMinutes++; currentSeconds = 0; currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes; } if(currentMinutes >59) { currentHours++; currentMinutes =0; } currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds; // Compose the string for display currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds; $("#clock").html(currentTimeString); } $(document).ready(function() { setInterval('updateClock()', 1000); });
You need to login to post a comment.
