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.

0

3 Answers 3

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);
1
  • Thanks Roberto Reale, I was using this method. I kept refreshing the wrong page, when testing it! Overtired, over worked. Thank you
    – bazbaz
    Commented Apr 28, 2014 at 8: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.

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.