0

I get the following string from a webservice, 2014-06-05T10:27:47Z. I want to add 2hours to this.

I tried to convert it to a date and add the time, but it doesn't work. Code below:

var d = new Date("2014-06-05T10:27:47Z");
d = new Date(d + 2*60*60*1000);

What am i doing wrong?

Lord Vermillion
  • 5,116
  • 17
  • 67
  • 105

2 Answers2

5

You can use setHours method:

var d = new Date("2014-06-05T10:27:47Z");
var d2 = new Date("2014-06-05T10:27:47Z");
d2.setHours ( d .getHours() + 2 );
Georgi Bilyukov
  • 645
  • 4
  • 11
5

Use the setHours and getHours methods of the Date object instead of trying to do it yourself.

var d = new Date("2014-06-05T10:27:47Z");

d.setHours(d.getHours() + 2)
Bakudan
  • 18,466
  • 9
  • 50
  • 71
vintastic
  • 521
  • 2
  • 7