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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:36:08+00:00 2026-05-22T23:36:08+00:00

I am creating a countdown to count the time between a match of the

  • 0

I am creating a countdown to count the time between a match of the euro2012 that I intend to watch.
I’ve come with a working version of it but I don’t understand why it gives me sometimes negative values.
I think it has to do with the way I wrote it, using the getTime() method.
Here is my code, could you guys help me find out to solve those negative values?
Thank you very much in advance.

<body onload="timeto2012()">
<script type="text/javascript">
 function timeto2012() {
 var euro2012 = new Date(2012, 5, 10, 20, 45);
 var euro2012ms = euro2012.getTime();
var now = new Date();
var nowms = now.getTime();

var diff = euro2012ms - nowms;

var seconds = 1000;
var minutes = seconds*60;
var hours = minutes*60;
var days = hours*24;
var years = days*365;

var ddays = diff/days;
var dhours = (ddays - Math.round(ddays,1))*24;
var dminutes = (dhours - Math.round(dhours))*60;
var dseconds = (dminutes - Math.round(dminutes))*60;

document.getElementById("time").innerHTML='' + Math.round(ddays,1) +' days '+ Math.round(dhours,1) +' hours '+ Math.round(dminutes,1) +' minutes '+ Math.round(dseconds,1) + ' seconds remaining';

}

t=setInterval(timeto2012,500);

</script>   
<div id="time"></div>
</body>
  • 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-22T23:36:08+00:00Added an answer on May 22, 2026 at 11:36 pm

    KOGI has the answer to your problem: You should use Math.floor instead of Math.round:

    When there’s x minutes and 30 – 59 seconds left, the (x - Math.round(x)) would be equivalent to (x - (x + 1)) after the rounding was done.

    var ddays = diff/days;
    var dhours = (ddays - Math.floor(ddays))*24;
    var dminutes = (dhours - Math.floor(dhours))*60;
    var dseconds = (dminutes - Math.floor(dminutes))*60;
    

    Fiddle: http://jsfiddle.net/YHktx/3/

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

Sidebar

Related Questions

I'm creating a countdown timer that allows the user to choose a valid time,
How would one go about creating a 15 second countdown timer..I've seen NSTimer but
I am creating an application. I am running a countdown timer and saving time
I am currently looking at creating a script for my site that will count
i need help creating a count down timer in php. the problem is that
I'm creating a countdown timer and I need to printout the time left (hour:minute:seconds)
I had this idea of creating a count down timer, like 01:02, on the
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
I have a a counter that needs to count up from $0 to $10,000
Creating a calculator-like dialog, I noticed that quickly clicking on a button in IE

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.