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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:12:37+00:00 2026-06-14T22:12:37+00:00

I am trying to display several count down timers on same page. now as

  • 0

I am trying to display several count down timers on same page. now as far as i know there are 2 ways of doing it without using jquery plugins or some other scripts (if you know of a good one please let me know)

  1. starting 1 sec setInterval and a global variable that will contain milliseconds and then just reduce -1000 every interval.

  2. creating a function that reduce 1 sec from a global variable and then at the bottom of that function setting a setTimeout of 1 sec that will run that functions so basically recursion every 1 sec.

My question is which of the 2 options will work better and/or faster?

here is demonstrative code for both:

setInterval:

var amount_of_seconds_left = 46800000;

setInterval(function(){
if(amount_of_seconds_left > 1000){
    amount_of_seconds_left -= 1000;
}
},1000);

setTimeout:

var amount_of_seconds_left = 46800000;
function startTime(){
if(amount_of_seconds_left > 1000){
    amount_of_seconds_left -= 1000;
    t=setTimeout(function(){startTime()},1000);
}
}

Both ways could work but i was wondering performance wise which is better and is performance is even an issue with this ?

  • 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-14T22:12:38+00:00Added an answer on June 14, 2026 at 10:12 pm

    setInterval and setTimeout don’t start after 1000ms e.g. if another script is running, so both can cause delays. It would be better to use the setIntervall to call the display update only and use the the Date object to calculate the exactly remaining time. E.g. after the browser was busy the timer shows the correct time after the next update.

    Here an example:

    HTML:

    <div id="timer1"></div>
    <div id="timer2"></div>
    

    javascript:

    // update all timer
    function updateTimer() {
        for (var i in aTimer) {
            var oTimer = document.getElementById(aTimer[i].sId);
            var iSeconds = parseInt((aTimer[i].iFinished - Date.now()) / 1000);
            oTimer.innerHTML = iSeconds;
        }
    }
    
    // Init all timers with DOM-id and finish time
    var aTimer = [
        { sId: 'timer1', iFinished: Date.now() + 46800000 },
        { sId: 'timer2', iFinished: Date.now() + 780000}
    ];
    
    // call display update
    setInterval(function() {
        updateTimer();
    }, 333);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to display several sliders with labels on the same line, eg: Label1:
I'm trying to make a page that would display several MotionJPEG image thumbnails. When
I am trying to aggregate several queries together to provide a latest updates display
Im trying to display some files in a web page so the user can
Using the form helper in CakePHP 1.3, I'm trying to display a list (drop-down
I have been trying several ways of displaying my json images but my solutions
In my project I'm trying to display several image files by manipulating the filename
I am trying to display several PNG Images on a JLayeredPane with overlapping. Here
I'm trying to display several chunks of data in columns next to each other.
I'm trying to display an ImageView in a dialog, I've followed several examples but

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.