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

178
Visualizações
Run function on a specific UTC +5:30 Time once

I have a function main(). I want to run this function at times 9:25,1:25,5:25 (considering 12 hour clock time-means 9:30 in the morning as well as at the night). As the clock hits any of the times mentioned above, the function should run once. Then the function should wait for next time. Like function runs at 9:30 in the morning (but only once and then stops) then it should wait for 1:25 in the afternoon. I want all this to be coded in Javascript. Is there any scheduler which will help me...

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

0

Do something like this:

var times = [[9, 25], [1, 25], [5, 25]];
var lastrun;

function checktime(){
    now = new Date(); // Get the current time
    if (lastrun != null){
        if (now-lastrun > 60000) return; // Wait until a minute has elapsed
        // (In order to avoid the function running twice within the same minute)
    }
    ok = false;
    for (time of times){ // Iterate through target times
        target = new Date(); // Create a new date where the target time will be held
        target.setHours(time[0]); // Set the hour and minute to the target time
        target.setMinutes(time[1]);
        if (now.getTime() >= target.getTime()){ // Check if the target time has been reached
            ok = true;
            break;
        }
    }
    if (ok){
        lastrun = now; // Store the time when the function was last run
        main(); // Run the main function if 'ok' is true
    }
}

setInterval(checktime, 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