Guest User

Horas em tempo real

a guest
Aug 26th, 2011
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.80 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Horas em tempo real com javascript!</title>
  6. <script>
  7. function showTime(){
  8.     var time = new Date();
  9.     var hour = time.getHours();
  10.     var minute = time.getMinutes();
  11.     var second = time.getSeconds();
  12.    
  13.     if(hour<10) hour = "0"+hour;
  14.     if(minute<10) hour = "0"+minute;
  15.     if(second<10) hour = "0"+second;
  16.     var tempo = hour+":"+minute+":"+second;
  17.    
  18.     document.getElementById("timer").innerHTML=tempo;
  19. }
  20. function initTime(){
  21.     setInterval(showTime, 1000);   
  22. }
  23. </script>
  24. </head>
  25.  
  26. <body onLoad="initTime();">
  27.     <span id="timer">Horas</span>
  28. </body>
  29. </html>
Advertisement
Add Comment
Please, Sign In to add comment