Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
How do I put 0 next to numbers less than 10 on a digital clock?

I wanted to make a digital live clock and I did it, but for numbers less than zero it does it without a 0 next to it, I want it to have zero next to it. For example: 18:35:05 I think we're going to add an if and write -- < 10, but I couldn't find what to write in the context of the condition.

function clock() {
    var hour = document.getElementById('hour');
    var minute = document.getElementById('minute');
    var second = document.getElementById('second');

    var h = new Date().getHours();
    var m = new Date().getMinutes();
    var s = new Date().getSeconds();

    hour.innerHTML = h;
    minute.innerHTML = m;
    second.innerHTML = s;
}
var interval = setInterval(clock, 1000);
.current-time {
    display: flex;
    position: relative;
    justify-content: space-between;
    width: 45%;
}
.time-text {
    display: table;
    position: relative;
    justify-content: flex-start;
    vertical-align: middle;
    margin: 0;
    width: 35%;
}
.time-text p {
    margin: 0;
}
#clock {
    display: table;
    position: relative;
    justify-content: flex-end;
    vertical-align: middle;
    margin: 0;
    width: 65%;
}
<html>
<body>
  <div class="current-time">
    <div class="time-text">
       <p>Time :</p>
    </div>
    <div id="clock">
       <span id="hour">00</span> :
       <span id="minute">00</span> :
       <span id="second">00</span>
     </div>
   </div>
</body>
</html>

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda