title: How to ISO 8601 format a Date with Timezone Offset in JavaScript?
body: <p><strong>Goal:</strong> Find the <code>local time</code> and <code>UTC time offset</code> then construct the URL in following format.</p>
  <p>Example URL: <code>/Actions/Sleep?duration=2002-10-10T12:00:00−05:00</code></p>
  <p>The format is based on the <a href="http://www.w3.org/TR/xmlschema11-2/#dateTime" rel="noreferrer">W3C recommendation</a>. The documentation says:</p>
  <blockquote>
  <p>For example, 2002-10-10T12:00:00−05:00 (noon on 10 October 2002,
  Central Daylight Savings Time as well as Eastern Standard Time in the U.S.)
  is equal to 2002-10-10T17:00:00Z, five hours later than 2002-10-10T12:00:00Z.</p>
  </blockquote>
  <p>So based on my understanding, I need to find my local time by <code>new Date()</code> then use <code>getTimezoneOffset()</code> function to compute the difference then attach it to the end of string.</p>
  <ol>
  <li><p>Get local time with <code>format</code></p>
  <pre><code>var local = new Date().format(&quot;yyyy-MM-ddThh:mm:ss&quot;); // 2013-07-02T09:00:00
  </code></pre>
  </li>
  <li><p>Get UTC time offset by hour</p>
  <pre><code>var offset = local.getTimezoneOffset() / 60; // 7
  </code></pre>
  </li>
  <li><p>Construct URL (time part only)</p>
  <pre><code>var duration = local + &quot;-&quot; + offset + &quot;:00&quot;; // 2013-07-02T09:00:00-7:00
  </code></pre>
  </li>
  </ol>
  <p>The above output means my local time is 2013/07/02 9am and difference from UTC is 7 hours (UTC is 7 hours ahead of local time)</p>
  <p>So far it seems to work but what if <code>getTimezoneOffset()</code> returns negative value like -120?</p>
  <p>I'm wondering how the format should look like in such case because I cannot figure out from W3C documentation.</p>