3

I am looking to add 5 hours & 30 mins to a certain time.

I have,

var d = new Date("Sun Apr 27 2014 16:47:53 GMT+0100");

any help would be much appreciated.

Ken Herbert
  • 5,205
  • 5
  • 28
  • 37
bazbaz
  • 53
  • 1
  • 2
  • 6

3 Answers3

12

Try this

var d = new Date("Sun Apr 27 2014 16:47:53 GMT+0100");
d.setHours(d.getHours() + 5);
d.setMinutes(d.getMinutes() + 30);
Roberto Reale
  • 4,247
  • 1
  • 17
  • 21
  • Thanks Roberto Reale, I was using this method. I kept refreshing the wrong page, when testing it! Overtired, over worked. Thank you – bazbaz Apr 28 '14 at 08:08
2

Also there is:

d.setTime(19800000);

The setTime() method uses milliseconds, but its easy to google seach the number of milliseconds. Though some of the answers above are more useful, this may come in handy for you down the road or for someone else.

Brendan
  • 1,399
  • 1
  • 12
  • 18
0

Just create a new date from your date object with the extra millis added on

e = new Date(d.getTime() + 1000 * 60 * 30 * 7);

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime

pherris
  • 17,195
  • 8
  • 42
  • 58