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?

2 Answers 2

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)
Sign up to request clarification or add additional context in comments.

Comments

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 );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.