Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

369
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!