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 8240551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:31:29+00:00 2026-06-07T20:31:29+00:00

I am trying to modify a script to run a countdown every 5 mins.

  • 0

I am trying to modify a script to run a countdown every 5 mins. Currently a getCountDown() function is set to counting down every 12 hours. I cant seems to figure out how to modify this time format to count down every 5 mins.
The function I need to change is here

function getCountDown() {
var until = getGMT();
until.setHours(until.getHours() < 12 ? 12 : 24, 0, 0, 0); // Next midday or midnight
return until;

function getGMT() {
var now = new Date();
now.setMinutes(now.getMinutes() + now.getTimezoneOffset() - 0 * 60); // GMT is UTC-0
return now;

}

My js skills are very limited so any help would be much appreciated.

  • 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-07T20:31:31+00:00Added an answer on June 7, 2026 at 8:31 pm

    Note: This answer is intended to guide the poster to the solution and a better understanding of JS, not to give the solution.

    The way the current code works is by first getting a date object and then setting the time on that object to either 24:00 (next midnight) or 12:00 (next noon). It works this out by checking what the current hours value is for the time (<12 means noon is next, otehrwise midnight is next). It then returns that newly modified date object showing the date that I presume the countdown is designed to run until.

    So the core of the problem is you need to return a different date object which means you want to set the minutes to something of your choosing (and the seconds and milliseconds to 0).

    For what you want to do you would be wanting to use the getMinutes and setMinutes functions on the Date Object to check the current date and then set the appropriate minute (and seconds and milliseconds values). Of course if your current time is 01:59 then you may need to change the hours to give 02:00 so you may in fact still want to use setHours (since this does allow you to set hours and minutes).

    To work out what your new minutes value is will hopefully be something you can do. You jsut need to round up to the nearest 5 and deal appropriately with the above mentioned situation where you are rounding up to an hour.

    Documentation on these above methods can be found on the msdn site:

    • setHours
    • getHours
    • getMinutes
    • setMinutes

    Edit to add some code

    var hours = until.getHours();
    var minutes = until.getMinutes();
    var targetMinutes = Math.ceil((minutes+1)/5)*5;
    if (targetMinutes==60)
    {
        targetMinutes = 0;
        hours = hours+1;
    }
    
    until.setHours(hours, targetMinutes, 0, 0);
    

    You might be able to write the above a little more efficiently and you might need to check what it does around boundaries like midnight properly too (it seems to work but you should always test code thoroughly). Hopefully you can understand what its up to. 🙂

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

Sidebar

Related Questions

I have trying to run the below script to modify the timestamp in the
I'm trying to modify the code from this script . Basically I'm trying to
I'm trying to modify an existing NSIS install script to allow for different licence
We're trying to modify out NANT build script to pull changes from our remote
I am trying to modify a batch script that installs a simple script file
In TFS 2008, I am trying to modify a build script (TFSBuild.proj). I get
I have a shopping cart script that I am trying to modify to support
I'm trying to modify an example in this website . I run this example
I'm trying to modify a ksh script to print out the line that contains
Hy everyone i've been trying for 2 days to modify this script so i

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.