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,264
  • 20
  • 69
  • 109

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
  • 19,134
  • 9
  • 53
  • 73
vintastic
  • 640
  • 3
  • 7