Advertisement
vinissh

desafio-relogio

Aug 11th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //console.log('Mensagem1');
  2.  
  3. /*window.setTimeout(function(){
  4.     console.log('Mensagem 2');
  5.  
  6. },3000);*/
  7.  
  8. /* Obtendo os id's para adicionar os códigos JS */
  9.  
  10. /*document.getElementById('mostrar-loader').onclick = function(){
  11.     document.getElementById('spinner-loader').style.display = "initial";
  12.  
  13.     window.setTimeout(function(){
  14.         document.getElementById('spinner-loader').style.display = "nome";
  15.  
  16.     },5000);
  17. };*/
  18.  
  19.  
  20. /*var count = 0;
  21.  
  22. var inter = window.setInterval(function(){
  23.     console.log(count);
  24.     count++;    
  25.     if(count >=10){
  26.  
  27.         window.clearInterval(inter);
  28.     }
  29.    
  30.  
  31. },1000);*/
  32.  
  33.  
  34. //Desafio do relogio
  35.  
  36. window.setInterval(function(){
  37.     var hora_atual = new Date();
  38.     var hora = hora_atual.getHours();
  39.     var minutos = hora_atual.getMinutes();
  40.     var segundos = hora_atual.getSeconds();
  41.  
  42.  
  43.     function format_time(time){
  44.         if(time>=0 && time <= 9){
  45.              var formatted_time = time.toString();
  46.              formatted_time = "0" + formatted_time;
  47.         }else{
  48.             var formatted_time = time.toString();
  49.         }
  50.  
  51.         return formatted_time;
  52.     }
  53.  
  54.     document.getElementById('relogio').innerHTML = format_time(hora) + ":" + format_time(minutos) +":"+ format_time(segundos);
  55.  
  56. },1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement