user1734190
user1734190

Reputation: 167

Getting issue to add time in existing date through jquery

I want to add the time 1 hours in existing date through jquery. I have tried javascript date object but didn't get the required result. I am using the following code.

 var sdate=new Date('2015-08-26T19:00');
 alert(sdate.getHours()+1);

I want to add 1 hours in 2015-08-26T19:00 date. Please let me know how I can get it

Upvotes: 2

Views: 57

Answers (3)

DinoMyte
DinoMyte

Reputation: 8858

This is what you need to do :

var sdate = new Date('2015-08-26T19:00');
var ndate = new Date(sdate.setHours(sdate.getHours() + 1));
alert(ndate);

Here's jsFiddle : http://jsfiddle.net/zo3hh2ye/13/

Upvotes: 2

IWillScoop
IWillScoop

Reputation: 258

From: https://stackoverflow.com/a/6734600/4888147

sdate.setHours(sdate.getHours() + hoursToAdd);

Upvotes: 0

Arijoon
Arijoon

Reputation: 2300

Fairly simple. Every hour is 60 Minutes. Each minute is 60 seconds. Each second is 1000 milliseconds. So every hour is 3600000 milliseconds. Now for date:

var sdate = new Date()
sdate.setMilliseconds(sdate.getMilliseconds()+3600000)

Upvotes: 1

Related Questions