Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda