0

How to convert a date like this: 2012-07-16 01:00:00 +00 (it's in the UTC +00:00 timezone) to the visitors timezone in Javascript, ensuring that daylight saving will be handelled correctly?

1 Answer 1

2

Break it into parts and use Date.UTC, e.g.

function fromUTC(s) {
  s = s.split(/[-: ]/g);
  return new Date(Date.UTC(+s[0], --s[1], +s[2], +s[3], +s[4], +s[5], 0));
}

var s = '2012-07-16 01:00:00 +00';

alert(fromUTC(s));
Sign up to request clarification or add additional context in comments.

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.