Advertisement
andmalv

Mostrar la hora actual en tiempo real

Oct 23rd, 2015
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function startTime() {
  2.     today = new Date();
  3.     h = today.getHours();
  4.     m = today.getMinutes();
  5.     s = today.getSeconds();
  6.     m = checkTime(m);
  7.     s = checkTime(s);
  8.     document.getElementById('reloj').innerHTML = h + ":" + m + ":" + s;
  9.     t = setTimeout('startTime()',500);
  10. }
  11.  
  12. function checkTime(i) {
  13.     if ( i < 10 ) {
  14.         i = "0" + i;
  15.     }
  16.  
  17.     return i;
  18. }
  19.  
  20. window.onload = function(){ startTime() ;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement