jjj
jjj

Reputation: 187

Javascript hours

$('#countdown').countdown("2013/12/25 20:00", function(event) {

I have that piece of code for my timer. But I want to have the current date and time plus one hour (rounded). It's kinda hard to explain but here is a example:

It is 17:49 the date will be 2013/12/25 18:00

It is 20:22 the date will be 2013/12/25 21:00

It is 14:02 the date will be 2013/12/25 15:00

Could someone help me with this? I'm really weak at javascript and I don't know where to start. I don't know if it's even possible.

Upvotes: 1

Views: 109

Answers (1)

scrblnrd3
scrblnrd3

Reputation: 7416

This will return a date object with the next hour

function nextHour(date) {

    date.setHours(date.getHours()+1);
    date.setMinutes(0);
    date.setSeconds(0);
    return date;
}
var date=new Date();
var nextDate=nextHour(new Date());
alert("it is "+date+", and it will be "+nextDate);

Obviously, you'll have to format the date a bit, but that shouldn't be that hard

Upvotes: 2

Related Questions