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

257
Views
Trying to create a 24h countdown timer that reset after deadline

I want to create a countdown to a set date and time. When the deadline arrives the timer will reset to 24 hours. Every day it will count down to 14:15.

This is the code below. Thanks in advance.

(function() {
  var deadline = '2021/12/30 14:15';

  function pad(num, size) {
    var s = "0" + num;
    return s.substr(s.length - size);
  }

  function getTimeRemaining(endtime) {
    var t = Date.parse(endtime) - Date.parse(new Date()),
      seconds = Math.floor((t / 1000) % 60),
      minutes = Math.floor((t / 1000 / 60) % 60),
      hours = Math.floor((t / (1000 * 60 * 60)) % 24),
      days = Math.floor(t / (1000 * 60 * 60 * 24));

    return {
      'total': t,
      'days': days,
      'hours': hours,
      'minutes': minutes,
      'seconds': seconds
    };
  }

  function clock(id, endtime) {
    let hours = document.getElementById(id + '-hours')
    let minutes = document.getElementById(id + '-minutes');

    var timeinterval = setInterval(function() {
      var time = getTimeRemaining(endtime);

      if (time.total <= 0) {
        deadline = "een datum"
        clearInterval(timeinterval);
      } else {
        hours.innerHTML = pad(time.hours, 2);
        minutes.innerHTML = pad(time.minutes, 2);
      }
    }, 1000);
  }

  clock('js-clock-header', deadline);

  function clocks(id, endtime) {
    let hours = document.getElementById(id + '-hours')
    let minutes = document.getElementById(id + '-minutes');

    var timeinterval = setInterval(function() {
      var time = getTimeRemaining(endtime);

      if (time.total <= 0) {
        clearInterval(timeinterval);
      } else {
        hours.innerHTML = pad(time.hours, 2);
        minutes.innerHTML = pad(time.minutes, 2);
      }
    }, 1000);
  }

  clocks('js-clock', deadline);
})();
<span id="js-clock-header-hours"></span>:<span id="js-clock-header-minutes"></span><br />
<span id="js-clock-hours"></span>:<span id="js-clock-minutes"></span>

about 4 years ago · Juan Pablo Isaza
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!