1

If given a date in UTC (let's say) is it possible to convert to various time zones taking DST into account?

I'm interested if JS can do this natively, without me having a list of time zones and their offset.

Thanks.

Francisc
  • 77,430
  • 63
  • 180
  • 276
  • 1
    possible duplicate of [Moment.js: Format date in a specific timezone](http://stackoverflow.com/questions/15347589/moment-js-format-date-in-a-specific-timezone) – PW Kad Apr 22 '14 at 17:30
  • 1
    Moment.js is a library. I'm hoping this has a solution without having to include a 3rd party dependency. – Francisc Apr 22 '14 at 17:33
  • 1
    Adding to @PWKad's comment: Timezones are a b****. The best idea is to use tested solutions like moment.js before building it yourself. – Ingo Bürk Apr 22 '14 at 17:33
  • @Francisc You could also perform DOM Manipulation without jQuery but that doesn't mean you should : ) – PW Kad Apr 22 '14 at 17:34
  • Yeah, but you first try without. Besides, this is what I was asking. – Francisc Apr 22 '14 at 17:35

2 Answers2

1

A date (in Javascript and in most other systems) is not "in" a particular timezone. It measures the number of milliseconds between midnight, January 1, 1970 GMT, and "now".

Timezone only comes into play when you want to convert it to or from a human-readable format.

Michael Lorton
  • 43,060
  • 26
  • 103
  • 144
0

You can use the getTimezoneOffset method.

dogiordano
  • 691
  • 6
  • 13
  • 1
    That returns the offset of the current machine (if set properly). It doesn't provide information about the name of the timezone for example. – Francisc Apr 22 '14 at 17:59