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

139
Views
Specific Hours CountdownTimer

I am trying to make a countdown timer that will show only from 8am till 16 and then show a message for 16hours and repeat the same loop every day. I have this code but I don't really get what is wrong with it. Any recommendations?

Appreciate. Thank you!

let getTom = () => {
var tom = new Date();    
tom.setDate(now.getDate() + (1 - now.getDay() % 1));
tom.setHours(16, 30, 0, 0); 
return tom; }

window.onload = function() {
var countDownDate = getTom();
let startCountdown = function() {
    // Countdown Timer
    var x = setInterval(function() {
        var now = new Date().getTime();
        var distance = countDownDate - now;
        var days = Math.floor(distance / (1000 * 60 * 60 * 24));
        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);
        var time =
            days + " days, " + hours + "h, " + minutes + "m, " + seconds + "s ";
        document.getElementById("time").innerText = time;
        if (distance < 0) {
            clearInterval(x);
            document.getElementById("time").innerText = "test";
            setTimeout(() => {
                startCountdown();
                // set to 16h later
                countDownDate = countDownDate.getTime() + (1000 * 60 * 60 * 16);
            }, (1000 * 60)) // 1m test
        }
    });

startCountdown();}}
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!