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

114
Visualizações
Auto Update when Passing Local Midnight in Javascript

I have a question about auto-updating data when passing local midnight.

Scenario

I am building a web app that contains daily practice content. Similar to Leetcode's everyday problem.

The daily practice will auto-update when passing local midnight.

Thoughts

I have searched a lot about repeating and auto-update posts. But most of them are related to setInterval which is mainly repeating after certain time duration, not to a certain time point.

There are two posts in the community:

How to make Javascript time automatically update

How to get date to auto refresh?


My naive solution:

If I could compromise, not updating exactly at local midnight, I can use setInterval with 24 hours. But it seems weird if a users found content updated at 2:00PM.

My question is: how to realize auto-update when passing local midnight?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Then calculate how much time until midnight, and setTimeout to it. Function from https://stackoverflow.com/a/8583781/3807365

function minutesUntilMidnight() {
  var midnight = new Date();
  midnight.setHours(24);
  midnight.setMinutes(0);
  midnight.setSeconds(0);
  midnight.setMilliseconds(0);
  return (midnight.getTime() - new Date().getTime()) / 1000 / 60;
}

var minutes = minutesUntilMidnight();
console.log(minutes.toFixed(2) + " minutes till midnight. that's " + (minutes / 60).toFixed(2) + " hours");
setTimeout(function() {
  window.location.reload();
}, minutes * 60 * 1000)

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