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

198
Views
Countdown repeat 48H from new date Javascript

I am trying to do a countdown in Javascript. I have the code now and it works fine, but I want to have more dates. So the first countdown is May 12, 2022 16:04:00, then I want a new 48h countdown from May 14, 2022 16:04:00, May 16, 2022 16:04:00 and so on. So when its May 12, 2022 16:04:01 I want a new 48h timer to start and countdown to May 14. Is this possible? Thanks for the help!

var countDownDate = new Date("May 12, 2022 16:04:00").getTime();

    var x = setInterval(function () {

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

        var distance = countDownDate - now;

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

        document.getElementById("hours").innerHTML = hours;
        document.getElementById("minutes").innerHTML = minutes;
        document.getElementById("seconds").innerHTML = seconds;

        if (distance < 0) { clearInterval(x); document.getElementById("countdown-text").innerHTML = "48H"; }
    }, 1000);
<div id="countdown">
                            <div class="countdown-hours">
                                <p id="hours"></p><span>hours</span>
                            </div>
                            <div class="countdown-minutes">
                                <p id="minutes"></p><span>minutes</span>
                            </div>
                            <div class="countdown-seconds">
                                <p id="seconds"></p><span>seconds</span>
                            </div>
                        </div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

var countDownDate = new Date("May 12, 2022 16:04:00").getTime();

var x = setInterval(function() {

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

  var distance = countDownDate - now;

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

  document.getElementById("hours").innerHTML = hours;
  document.getElementById("minutes").innerHTML = minutes;
  document.getElementById("seconds").innerHTML = seconds;

  if (distance < 0) {
    var numberOfMlSeconds = new Date().getTime();
    var addMlSeconds = 48 * 60 * 60 * 1000;
    countDownDate = new Date(numberOfMlSeconds + addMlSeconds);
  }
}, 1000);
<div id="countdown">
  <div class="countdown-hours">
    <p id="hours"></p><span>hours</span>
  </div>
  <div class="countdown-minutes">
    <p id="minutes"></p><span>minutes</span>
  </div>
  <div class="countdown-seconds">
    <p id="seconds"></p><span>seconds</span>
  </div>
</div>

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!