Guest User

Relogio em tempo real

a guest
Jul 28th, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3. <title>Relogio em Tempo Real</title>
  4. </head>
  5. <script>
  6.  function showTimer() {
  7.   var time=new Date();
  8.   var hour=time.getHours();
  9.   var minute=time.getMinutes();
  10.   var second=time.getSeconds();
  11.   if(hour<10)   hour  ="0"+hour;
  12.   if(minute<10) minute="0"+minute;
  13.   if(second<10) second="0"+second;
  14.   var st=hour+":"+minute+":"+second;
  15.   document.getElementById("timer").innerHTML=st;
  16.  }
  17.  function initTimer() {
  18.   // O metodo nativo setInterval executa uma determinada funcao em um determinado tempo  
  19.   setInterval(showTimer,1000);
  20.  }
  21. </script>
  22. <body onLoad="initTimer();">
  23. Exemplo de Relógio em tempo real utilizando a TAG 'span' e o método setInterval.
  24. <br><br>
  25. <span id="timer">Relógio</span>
  26. </body>
  27.  
  28. </html>
Advertisement
Add Comment
Please, Sign In to add comment