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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:54:33+00:00 2026-06-15T18:54:33+00:00

I have jquery countdown which I took from here and tried to modify with

  • 0

I have jquery countdown which I took from here and tried to modify with cookie to get persistent result as following:
Edited

   <script type="text/javascript">
    (function($) {
   function countdown(el, options) {
    var calc = function (target, current) {
        var o = {};

        var datetarget = getCookie('Target');
        if(!datetarget) {
            clearInterval(cd.id);
            var datetarget = target.getTime()/1000;
        }
        if(datetarget <= 0) { return true; }
        deleteCookie('Target');
        o.seconds = datetarget;
        o.seconds %= 86400;
        o.hours = Math.floor(o.seconds/3600);
        o.seconds -= o.hours * (3600);
        o.minutes = Math.floor(o.seconds/60);
        o.seconds -= o.minutes * (60);
        o.seconds %= 60;
        datetarget -= 1;
        setCookie('Target',datetarget,1);
        return o;
    };

It somehow worked but i still got float instead of integer on “seconds” part and wrong result on “hours”. Any ideas?

  • 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-15T18:54:34+00:00Added an answer on June 15, 2026 at 6:54 pm

    I still got float instead of integer on “seconds” part

    You never rounded it. While the milliseconds you got from getTime were an integer, you got a float with 3 decimals after dividing by 1000 to convert to seconds.

    Also, the EcmaScript Modulus operator does work on floats, instead of truncating operands and result to integers. To cite the spec:

    In C and C++, the remainder operator accepts only integral operands;
    in ECMAScript, it also accepts floating-point operands.

    The result of a floating-point remainder operation as computed by the
    % operator is not the same as the “remainder” operation defined by
    IEEE 754. The IEEE 754 “remainder” operation computes the remainder
    from a rounding division, not a truncating division, and so its
    behaviour is not analogous to that of the usual integer remainder
    operator. Instead the ECMAScript language defines % on floating-point
    operations to behave in a manner analogous to that of the Java integer
    remainder operator; this may be compared with the C library function
    fmod.

    Where neither an infinity, nor a zero, nor NaN is involved […], the
    floating-point remainder r from a dividend n and a divisor d is
    defined by the mathematical relation r = n − (d * q) where q is an
    integer that is negative only if n/d is negative and positive only if
    n/d is positive, and whose magnitude is as large as possible without
    exceeding the magnitude of the true mathematical quotient of n and d.
    r is computed and rounded to the nearest representable value using
    IEEE 754 round-to-nearest mode.

    That last part also explains why we likely get some other decimals from small rounding errors in the floating point arithmetic.

    You may omit one of the equivalent lines

        o.seconds -= o.minutes * (60);
        o.seconds %= 60;
    

    and add one of

        o.seconds = Math.round(o.seconds);
        o.seconds = Math.floor(o.seconds);
    

    wrong result on “hours”

    I can’t see that. Might it be possible that you did expect the value behave according your timezone? getTime returns milliseconds since epoch, which is in UTC.

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

Sidebar

Related Questions

I am using the jquery countdown timer here http://www.littlewebthings.com/projects/countdown/ and I have found that
I have the following inline javascript, im using a jquery countdown plugin to display
I have JQuery UI Dialog opening on pressing CTRL + Q using the following
I have jQuery code which looks something like this on Button1 Click $('table.result_grid tbody
I have jquery validation code which is working fine in ff but the same
i have problem with my script using jquery.countdown.js plugin, it doesn't sets multiple instances
I have jQuery code which works offline in Safari and Opera, but neither in
I have a jquery timer on my page that counts down from 10 to
I have a this working countdown timer in jQuery but for now I'm just
I want to do two things using a countdown in jQuery. I have looked

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.