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

364
Visualizações
How to get current server time in JS

when I change the time on my laptop or PC, the countdown time also changes, how do I solve the problem with the code below? thank you master.

var end_of_time = new Date("2022-01-30 10:00:00").getTime();

var x_user = setInterval(function() {

    var time_now = new Date().getTime();

    var distance = end_of_time - time_now;

    var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = Math.floor((distance % (1000 * 60)) / 1000);

    document.getElementById("countdown").innerHTML = "Remaining " + hours + "h "
    + minutes + "m " + seconds + "s ";

    if (distance < 0) {
        document.getElementById("countdown").innerHTML = "Expired";
    }

}, 1000);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  1. Don't rely on javascript for date calculations when you run in the browser.

  2. Think of rendering this page from the server side.

  3. Or, if you are running an application in the browser (client-side), think of exposing a REST API to get the time from the server and proceed with calculations in UI.

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