Reputation: 5
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
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
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
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