Dipak-user3085702
Dipak-user3085702

Reputation: 5

How to add hours to the given date using jquery?

I have a date 2015-7-15 and I want to add 9 hours to the given date I am trying but not getting result please help me.

Upvotes: 0

Views: 12321

Answers (3)

Ankur Tiwari
Ankur Tiwari

Reputation: 2782

Try this code

date.setMinutes(date.getMinutes()+ add 9 hour in minutes);

And I suggest to use time in UNIX time stamp.

Upvotes: 1

Andrêves Dickow
Andrêves Dickow

Reputation: 170

I created this function:

Date.prototype.addHours(h) {
   this.setHours(this.getHours() + h);
   return this;
}

and I called

alert(new Date().addHours(5));

Upvotes: 2

Marikkani Chelladurai
Marikkani Chelladurai

Reputation: 1430

You can get your answer by googling.

var myDate = new Date();

OR if you have the date, month and year, create a date as

var myDate = new Date(year, month, date);

then you can add the hours to your date

myDate.setHours(myDate.getHours()+h);

will do that

Upvotes: 3

Related Questions