Jo Smo Jo Smo - 1 year ago 96
Javascript Question

How to convert UTC datetime (string) into the visitors timezone?

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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download