Posted By

rajhans on 11/26/10


Tagged

counter Stopwatch


Versions (?)

stopwatch counter in jquery


 / Published in: jQuery
 

  1. var currentHours = 0;
  2. var currentMinutes = 0;
  3. var currentSeconds = 0;
  4. currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  5. currentHours = ( currentHours < 10 ? "0" : "" ) + currentHours;
  6.  
  7. function updateClock ( )
  8. {
  9.  
  10. currentSeconds++;
  11.  
  12. if(currentSeconds >59)
  13. {
  14. currentMinutes++;
  15. currentSeconds = 0;
  16. currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  17. }
  18. if(currentMinutes >59)
  19. {
  20. currentHours++;
  21. currentMinutes =0;
  22. }
  23.  
  24.  
  25.  
  26. currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
  27.  
  28. // Compose the string for display
  29. currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds;
  30.  
  31. $("#clock").html(currentTimeString);
  32.  
  33. }
  34.  
  35. $(document).ready(function()
  36. {
  37. setInterval('updateClock()', 1000);
  38. });

Report this snippet  

You need to login to post a comment.