0

I'm working with an API which returns dates in the following format:

2017-07-28T12:36:17Z

I'm used to working with unix timestamps. What I need to do ultimately is add an hour to the time segment in order to account for British Summer Time.

How can I cast this data as a date, add an hour and then output the time segment?

3 Answers 3

2

console.log(new Date('2017-07-28T12:36:17Z').setUTCHours(1))

for British Summer Time (BST) use .setUTCHours(1) . Check setUTCHours()

Sign up to request clarification or add additional context in comments.

Comments

1

You can use Date() function

var d = new Date('2017-07-28T12:36:17Z');
console.log(d);
d.setHours(d.getHours()+1);
console.log(d);

Comments

0

This is a UTC formatted date, which includes a time string.

You can cast this as a JavaScript date using the Date constructor, e.g:

var testDate = new Date('2017-07-28T12:36:17Z');
console.log(testDate) // Fri Jul 28 2017 13:36:17 GMT+0100 (GMT Daylight Time)

Once it is a JS Date object, you can manipulate it as you need.

1 Comment

Here Date value will return according to your local time zone not in BST.

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.