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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:51:40+00:00 2026-05-31T17:51:40+00:00

I made this little function from code snippets around the net. It does what

  • 0

I made this little function from code snippets around the net. It does what its expected to do except that it decreased by 2 seconds every countdown tick instead of one, if i refresh the page it goes back to the original time again. Can you guys see what the problem is?

                jQuery.countdown = function(selector, datevalue) {

                var amount = datevalue*1000;

                var curdate = new Date();
                curdate     =   curdate.getTime();

                var difference = amount - curdate;


                if(amount < 0 || curdate >= amount){
                    $(selector).html("Done");
                }


                else{
                    datevalue--;

                    var daysRemaining = Math.floor(difference / 1000 / 60 / 60 / 24);
                    var hoursRemaining = Math.floor(difference / 1000 / 60 / 60 - (24 * daysRemaining));
                    var minutesRemaining = Math.floor(difference / 1000 / 60 - (24 * 60 * daysRemaining) - (60 * hoursRemaining));
                    var secondsRemaining = Math.floor(difference / 1000 - (24 * 60 * 60 * daysRemaining) - (60 * 60 * hoursRemaining) - (60 * minutesRemaining));

                    $(selector).html(daysRemaining+':'+hoursRemaining+':'+minutesRemaining+':'+secondsRemaining);
                    setTimeout(function() {  
                        $.countdown(selector, datevalue);
                    }, 1000); 
                }
};




$.countdown('.date', 1332239568);
  • 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-05-31T17:51:41+00:00Added an answer on May 31, 2026 at 5:51 pm

    Remove datevalue--;

    What you’re doing now is to count down to a specific epoch time datevalue. But, you are decreasing it by one second each tick. Meanwhile, current time passes in setTimeout so you are both moving in time forward and pulling the target to yourself.

    Either keep the original curdate of first call, saved somewhere. Or remove datevalue--;.

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

Sidebar

Related Questions

I've made a little function that sends data from two forms to a PHP
I made this little Cocoa app with a WebView that displays Google Maps in
I made this function to verify a user's twitter credentials. Its running on two
It's often the case that I can write a nice tight little VB.NET function,
I made this little function: public String getDay() { String day = (String)android.text.format.DateFormat.format(E, new
I've made this little plugin to show Twitter style alerts: jQuery.fn.myAlert = function (options)
Made this nice little loop for hiding and showing div's, works as a charm
I made this code with jQuery to fade images ( but not the one
I made this bookmarklet: javascript:(function(){var s=document.createElement('script');s.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');document.getElementsByTagName('body')[0].appendChild(s);$('#hldIntMain').hide();$('#fadeBackground').hide();return false;})() Formatted code: // Add in jQuery var
I've made a program for my OOP class that does the following: Defines a

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.