JS Stopwatch (Chronometre)

JS Stopwatch (Chronometre) - HTML/CSS - Programmation

Marsh Posté le 18-01-2008 à 21:33:57    

Io les gens.
 
Bon me suis fait un script pour avoir un chrono, dans mon appli.
 
Me suis dis, jouer avec Date, pour la gestion, c'estle mieux...mais maybe il y a encore plus simple:
 
Script a l'arache :
 

Code :
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. var today=new Date();
  5. var startT=today.getTime();
  6. function startTime()
  7. {
  8. var today2=new Date();
  9. today.setTime(today2.getTime()-startT);
  10. var h=today.getUTCHours();
  11. var m=today.getUTCMinutes();
  12. var s=today.getUTCSeconds();
  13. m=checkTime(m);
  14. s=checkTime(s);
  15. h=checkTime(h);
  16. document.getElementById('txt').innerHTML=h+":"+m+":"+s;
  17. t=setTimeout('startTime()',500);
  18. }
  19. function checkTime(i)
  20. {
  21. if (i<10)
  22.   {
  23.   i="0" + i;
  24.   }
  25. return i;
  26. }
  27. </script>
  28. </head>
  29. <body onload="startTime()">
  30. <div id="txt"></div>
  31. </body>
  32. </html>


thx

Reply

Marsh Posté le 18-01-2008 à 21:33:57   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed