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

365
Vistas
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 Respuestas
Responde la pregunta

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 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