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

153
Vistas
Timer every hour but starting from 1 minute

I would like to create a countdown timer for my resource. An example for this I took from Quasimodo's clone answer of this page.

From the code, I took some elements, since I only need minutes and seconds. And I don't need a 30 minute mark.

The code works great, but unlike the author of the question, I need the start to start and end at 1 minute of the next hour.

The changes that I made did not lead to the desired result:

secsRemaining = 3600 - (time.getUTCMinutes()+1)%60 * 60 - time.getUTCSeconds(),

and

mins = (Math.floor(secsRemaining / 60)+60),

This gave a result, but not the one that is needed. When the time on the clock becomes 00 minutes, then the code becomes 60 minutes and 00+ seconds. I need, for example, at 14:00:59 the timer has the values ​​00:01, and when 14:01:01 the timer has the values ​​59:59.

Please let me know how it can be changed to achieve the desired result. Perhaps you have a link to solutions. I couldn't find it on the Internet.

Code I am using:

var byId = document.getElementById.bind(document);

function updateTime() {
  var time = new Date(),
    secsRemaining = 3600 - (time.getUTCMinutes()) % 60 * 60 - time.getUTCSeconds(),
    mins = (Math.floor(secsRemaining / 60)),
    secs = secsRemaining % 60;
  byId('min-part').textContent = mins;
  byId('sec-part').textContent = secs;
  setTimeout(updateTime, 1000 - (new Date()).getUTCMilliseconds()).toLocaleString();
}
updateTime();
<div>Time left before update: <span id="min-part"></span>:<span id="sec-part"></span></div>

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

If I understood well your needs, this should be the code you need:

var byId = document.getElementById.bind(document);

function updateTime()
{
  var
    time = new Date(),
    // You need an hour of countdown, so 30 becomes 60
    secsRemaining = 3600 - (time.getUTCMinutes()+60)%60 * 60 - time.getUTCSeconds(),
    // integer division
    // you want the timer to "end" at minute 1, so add 1 minute to the minutes counter
    mins = (Math.floor(secsRemaining / 60) + 1) % 60, 
    secs = secsRemaining % 60
  ;
  byId('min-total').textContent = secsRemaining;
  byId('min-part').textContent  = mins;
  byId('sec-part').textContent  = secs;

  // let's be sophisticated and get a fresh time object
  // to calculate the next seconds shift of the clock
  setTimeout( updateTime, 1000 - (new Date()).getUTCMilliseconds() );
}
updateTime();
about 4 years ago · Juan Pablo Isaza Denunciar

0

Here is how I would do it

  • Generating a date at the next hour and 1 minutes
  • Calculating the number of millisecond between the current date and the next date
  • Display the time remaining

const minutes = document.getElementById('minutes')
const seconds = document.getElementById('seconds')

setInterval(() => {
  const now = new Date()
  const nextHours = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours() + 1, 1)
  const nbMilisec = (nextHours - now)

  const nbMinutes = parseInt((nbMilisec / 1000 / 60) % 60)
  const nbSeconds = parseInt((nbMilisec / 1000)  % 60)
  
  
  minutes.innerHTML = String(nbMinutes).padStart(2, '0')
  seconds.innerHTML = String(nbSeconds).padStart(2, '0')
}, 1000)
<div id="time">
  Time left before update : <span id="minutes"></span> : <span id="seconds"></span>
</div>

about 4 years ago · Juan Pablo Isaza Denunciar
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