Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9225815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:40:25+00:00 2026-06-18T04:40:25+00:00

I need a timer to countdown 4 hours at a time and then restart

  • 0

I need a timer to countdown 4 hours at a time and then restart after hitting 0. The time remaining needs to be the same across all clients. I’ve currently got this:

function addZero(i) {
  if (i < 10) {
    i = "0" + i;
  }
  return i;
}
setInterval(function() {
  function addZero(i) {
    if (i < 10) {
      i = "0" + i;
    }
    return i;
  }
  var d = new Date();
  var s = (d.getSeconds());
  var m = (d.getMinutes());
  var x = document.getElementById("timer");
  var c = addZero(30 - m) + ":" + addZero(60 - s);
  var d = addZero(60 - m) + ":" + addZero(60 - s);
  if (m < 30) {
    t = c
  } else {
    t = d
  }

  x.innerHTML = t;
}, 250)
<div align="center">
  <table>
    <tbody>
      <td style="font-size:15px;">Time to next restart:</td>
      <td style="font-size:16px;" id="timer"></td>
      <td nowrap="nowrap" width="15px">
        <p style="text-align: left;"></p>
      </td>
    </tbody>
  </table>
</div>

Which counts down 30 minutes and then resets back to 30. However when it hits the last second it counts the 60, instead of going to straight to 59 (so 4:00/3:60/3:59). Also it needs to countdown beginning at noon (12pm) EST. I would like the time to display in h:mm:ss format, I’m missing the hour on the above code as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:40:26+00:00Added an answer on June 18, 2026 at 4:40 am

    Use PHP to get the date/time on initial page load, rather than client/JS Date() – this could be wildly different across machines, so it’s worthless if you want clients synchronised (the PHP date will come from the server clock, so provided it’s correct, you can sync multiple clients to it). Even taking this time as a base and then counting down four hours on the client is not likely to result in well-synced time – I would refer periodically to the server to sync it up.

    As for your problem with it displaying 60, can you not just replace the figures in your code
    like so:

    var d = addZero(60 - m) + ":" + addZero(60 - s);
    

    becomes

    var d = addZero(59 - m) + ":" + addZero(59 - s); 
    

    ?

    Seeing as the return values will always be 0-59, this will just reverse it, you won’t get a minus figure, it will display what a digital clock actually would (you never see them get to 60 mins/secs, they reset to 0).

    I’d do the minute/second counting with JS, as it’s pointless referring to the server so regularly – if, when you do sync, you notice a disrepancy, it’s not likely to be too high if you don’t leave it a long time (like 4 hours) between checks.

    What is this actually for?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to set a countdown timer. The time remaining in the format of
I'm creating a countdown timer and I need to printout the time left (hour:minute:seconds)
I am making a contest platform ..For it I need a countdown timer ..The
I write a countdown timer in jQuery and i need to keep some datas
I'm creating a countdown timer that allows the user to choose a valid time,
I need to create a countdown clock, that counts down the days, hours, minutes
I am using countdown timer in my application where i need to display upcoming
I need a timer implemented in my application, which will do a countdown from
I am Implementing a countdown timer in my app. In the functionality, I need
I have a countdown timer with days, hours, minutes and seconds. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.