Advertisement
zbte

Horas em tempo real

Apr 21st, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2.  
  3. <html>
  4.     <head>
  5.         <script>
  6.             window.onload = timer();
  7.  
  8.             function exibirData() {
  9.                 var tempo = new Date();
  10.                 var horas = tempo.getHours();
  11.                 var minutos = tempo.getMinutes();
  12.                 var segundos = tempo.getSeconds();
  13.  
  14.                 if(horas < 10)
  15.                     horas = "0" + horas;
  16.                 if(minutos < 10)
  17.                     minutos = "0" + minutos;
  18.                 if(segundos < 10)
  19.                     segundos = "0" + segundos;
  20.  
  21.                 var mostrar = horas + ":" + minutos + ":" + segundos;
  22.                 document.getElementById("exibir").innerHTML = mostrar;
  23.             }
  24.  
  25.             function timer() {
  26.                 setInterval(exibirData, 1000);
  27.             }
  28.         </script>
  29.     </head>
  30.     <body>
  31.         <span id = "exibir"></span>
  32.     </body>
  33. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement