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 in Web Development by gaurav
• 17,580 points
6 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 by rajatha
• 7,040 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 in Web Development by rajatha
• 7,040 points
21 views
0 votes
1 answer

jQuery get value of select onChange

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

answered Jun 23 in Web Development by rajatha
• 7,040 points
18 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 in Web Development by rajatha
• 7,040 points
11 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 in Web Development by rajatha
• 7,040 points
57 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 in Web Development by rajatha
• 7,040 points
13 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 in Web Development by rajatha
• 7,040 points
23 views
0 votes
0 answers

Javascript/Jquery returning tomorrows date, but skip Sundays

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

Jul 28 in Web Development by gaurav
• 17,580 points
6 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

3 days ago in Web Development by gaurav
• 17,580 points
6 views
0 votes
1 answer

Microsoft CDN for jQuery or Google CDN?

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

answered Jun 22 in Web Development by rajatha
• 7,040 points
28 views
0 votes
1 answer

Get checkbox value in jQuery

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

answered Jun 23 in Web Development by rajatha
• 7,040 points
17 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP