jQuery Countdown get time until 10 00 am today or tomorrow

0 votes

I need a little script and I am a little confused.

I want to use this plugin: http://keith-wood.name/countdown.html

Goal: Have a Countdown, that counts from now to 10:00 am - if it's 0-9:59:59 am count to 10 o'clock today if it's after 10:00:00 count to 10:00 tomorrow. Is that understandable?

Here's what I need with javascript / jquery (this will not work, i know):

var currentDate = new Date(new Date().getTime());
var hours = currentDate.getHours();
var endTime;
    if(hours >= 10){
        endTime = give me next day 10:00
    } else {
        endTime = give me this day 10:00
    }
$("#countdown").countdown({until: endTime, format: 'HMS'});

Aug 4, 2022 in Web Development by gaurav
• 23,260 points
1,397 views

1 answer to this question.

0 votes

The following should work (console.log() was added for testing purposes). Beware that it will use the timezone of the browser instead of UTC time.

var currentDate = new Date(new Date().getTime());
var hours = currentDate.getHours();
var endTime = new Date(currentDate);
endTime.setMinutes(0);
endTime.setSeconds(0);
endTime.setHours(10);

if(hours >= 10){
    endTime.setDate(endTime.getDate() + 1);
}
console.log(endTime);
$("#countdown").countdown({until: endTime, format: 'HMS'});
answered Aug 4, 2022 by rajatha
• 7,640 points

Related Questions In Web Development

0 votes
1 answer

jQuery get value of select onChange

Try this- $('select').on('change', function() { alert( this.value ...READ MORE

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

jQuery get value of select onChange

To get the value and text of ...READ MORE

answered Jun 23, 2022 in Web Development by rajatha
• 7,640 points
872 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,640 points
486 views
0 votes
1 answer

jQuery get value of selected radio button

Input Radio value Property Get the value of ...READ MORE

answered Jun 23, 2022 in Web Development by rajatha
• 7,640 points
2,418 views
0 votes
1 answer

Get current date in DD-Mon-YYY format in JavaScript/Jquery

Get Current Date In DD-Mon-YYY Format In ...READ MORE

answered Jun 28, 2022 in Web Development by rajatha
• 7,640 points
910 views
0 votes
1 answer

Get current date in DD-Mon-YYY format in JavaScript/Jquery

get current date in jquery in dd/mm/yyyy ...READ MORE

answered Jun 27, 2022 in Web Development by rajatha
• 7,640 points
5,510 views
0 votes
0 answers

Javascript/Jquery returning tomorrows date, but skip Sundays

I want to get tomorrows date, but ...READ MORE

Jul 28, 2022 in Web Development by gaurav
• 23,260 points
264 views
0 votes
0 answers

jQuery Count Down timer based on Remaining Days, Hours, Minutes and Seconds

I'm creating a system where I have ...READ MORE

Aug 11, 2022 in Web Development by gaurav
• 23,260 points
1,289 views
0 votes
1 answer

Microsoft CDN for jQuery or Google CDN?

You should absolutely use the Google CDN ...READ MORE

answered Jun 22, 2022 in Web Development by rajatha
• 7,640 points
463 views
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,640 points
439 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