Countdown till midnight in Jquery

0 votes

I have a simple question, that is giving me some problems. I am trying to configure a countdown timer, so that it would show the remaining hours, seconds and minutes. I got some great code online, but I have to modify it, so that it is dependant of the current time and not the time when somebody visits the site.
The code I use is this: http://tutorialzine.com/2011/12/countdown-jquery/

I have been working on the script.js and corrected this:

$(function(){

    var note = $('#note'),
        ts = new Date(2012, 0, 0,0,0),
        newYear = true;

    if((new Date()) > ts){
        // The new year is here! Count towards something else.
        // Notice the *1000 at the end - time must be in milliseconds
        var uraJe = new Date();
        var ura = 24 - uraJe.getHours();
        var minute = 60 - uraJe.getMinutes();
        var sekunde = 60 - uraJe.getSeconds();
        ts = (new Date()).getTime() + ura*60*60*1000;
        newYear = false;
    }

    $('#countdown').countdown({
        timestamp   : ts,
        callback    : function(days, hours, minutes, seconds){

            var message = "";

            note.html(message);
        }
    });

});

When I run it, it does show the hours correctly, but the minutes are not.

How can I correct that?

Jul 25, 2022 in Web Development by gaurav
• 23,260 points
596 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

So if you want ts to be midnight of the current/next day, you can use setHours() on a date object of the current day.

var today = new Date(); 
today.setHours(23, 59 ,59, 1000); 

This will result in today being the beginning of the next day, because of 1000ms. If you want the date to stay on the current day you can use 999ms

answered Jul 28, 2022 by rajatha
• 7,680 points

edited Mar 5

Related Questions In Web Development

0 votes
1 answer

Get checkbox value in jQuery

To get the value of the Value ...READ MORE

answered Jun 23, 2022 in Web Development by rajatha
• 7,680 points
789 views
0 votes
1 answer

Get checkbox value in jQuery

if you have set a class or id for it, you ...READ MORE

answered Jun 23, 2022 in Web Development by rajatha
• 7,680 points
848 views
0 votes
1 answer

JQuery Ajax Post results in 500 Internal Server Erro

The 500 Internal Server Error is a ...READ MORE

answered Jun 23, 2022 in Web Development by rajatha
• 7,680 points
32,737 views
0 votes
1 answer

explode string in jquery

Use the JavaScript split() method If you want ...READ MORE

answered Jun 23, 2022 in Web Development by rajatha
• 7,680 points
3,199 views
0 votes
1 answer

how to use substr() function in jquery?

To get substring of a string in ...READ MORE

answered Jun 27, 2022 in Web Development by rajatha
• 7,680 points
1,381 views
0 votes
1 answer

How to loop through array in jQuery?

Generic loop: var i; for (i = 0; i ...READ MORE

answered Jun 28, 2022 in Web Development by rajatha
• 7,680 points
2,373 views
0 votes
1 answer

How to use jquery with asp.net ajax?

If you weren't aware, Microsoft is planning ...READ MORE

answered Oct 15, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
860 views
0 votes
1 answer

Is 'sparkline' a method?

I suggest you to check 2 things That jquery.sparkline.js is actually ...READ MORE

answered Nov 9, 2018 in Apache Spark by Frankie
• 9,830 points
1,500 views
0 votes
1 answer

What is jQuery?

Hey, jQuery is a fast and concise JavaScript ...READ MORE

answered Feb 14, 2020 in JQuery by kartik
• 37,520 points
1,581 views
0 votes
1 answer

Error: Global Variable is not accessable to local function

Hey kartik, A variable declared outside a function has a ...READ MORE

answered Feb 19, 2020 in PHP by Niroj
• 82,840 points
1,206 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP