title: Working with timezones and daylight savings time in Javascript
body: <p>My single-page javascript app retrieves data in JSON format via REST calls. Dates come formatted using the UTC timezone in standard ISO8601 format, such as <code>2011-02-04T19:31:09Z</code>.</p>
  
  <p>When signing up for the service, users select their timezone from a drop down list. This timezone could be different than the user's browser's timezone. The javascript app knows what the user's selected timezone is at all times.</p>
  
  <p>I know how to convert the UTC string into a date. I understand that Javascript only represents dates in the local timezone. </p>
  
  <p>But I'm having troubles figuring out <strong>how to display a date formatted for a timezone OTHER than the user's local timezone</strong>. It must account for DST on all dates. Internally, I want to deal with all dates as UTC and only convert to string representation of a date in another timezone at display time. I need to display the dates in the timezone selected in the user's profile, not their browser's timezone.</p>
  
  <p>I've experimented with the server sending the timezone offset difference in milliseconds between the user's browser's timezone and the user's profile timezone. But I've found I can't just send one offset value, but need to send an offset for every date to account for variations in DST.</p>
  
  <p>Any suggestions or sample code on how to display dates formatted in various timezones? The options I've found so far:</p>
  
  <ol>
  <li>Server sends dates as strings already formatted in the right timezone and no date parsing or manipulation is done on the client. This makes doing certain things on the client difficult if not impossible.</li>
  <li>Use a library such as <a href="https://github.com/mde/timezone-js" rel="noreferrer">https://github.com/mde/timezone-js</a>, which includes the entire Olson TZ database into Javascript. This means longer load times more memory usage, etc.</li>
  <li>Send a timezoneOffsetMillis value with every date sent to the client. This results in messy JSON data and non-optimal REST interfaces.</li>
  </ol>
  
  <p>Are there any simpler or better solutions?</p>