title: How can I parse / create a date time stamp formatted with fractional seconds UTC timezone (ISO 8601, RFC 3339) in Swift?
body: <p>How to generate a date time stamp, using the format standards for <a href="http://en.wikipedia.org/wiki/ISO_8601" rel="noreferrer">ISO 8601</a> and <a href="https://www.rfc-editor.org/rfc/rfc3339" rel="noreferrer">RFC 3339</a>?</p>
  <p>The goal is a string that looks like this:</p>
  <pre><code>&quot;2015-01-01T00:00:00.000Z&quot;
  </code></pre>
  <p>Format:</p>
  <ul>
  <li>year, month, day, as &quot;XXXX-XX-XX&quot;</li>
  <li>the letter &quot;T&quot; as a separator</li>
  <li>hour, minute, seconds, milliseconds, as &quot;XX:XX:XX.XXX&quot;.</li>
  <li>the letter &quot;Z&quot; as a zone designator for zero offset, a.k.a. UTC, GMT, Zulu time.</li>
  </ul>
  <p>Best case:</p>
  <ul>
  <li>Swift source code that is simple, short, and straightforward.</li>
  <li>No need to use any additional framework, subproject, cocoapod, C code, etc.</li>
  </ul>
  <p>I've searched StackOverflow, Google, Apple, etc. and haven't found a Swift answer to this.</p>
  <p>The classes that seem most promising are <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/index.html" rel="noreferrer"><code>NSDate</code></a>, <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/index.html" rel="noreferrer"><code>NSDateFormatter</code></a>, <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSTimeZone_Class/index.html" rel="noreferrer"><code>NSTimeZone</code></a>.</p>
  <p>Related Q&amp;A: <a href="https://stackoverflow.com/questions/16254575/how-do-i-get-iso-8601-date-in-ios">How do I get an ISO 8601 date on iOS?</a></p>
  <p>Here's the best I've come up with so far:</p>
  <pre><code>var now = NSDate()
  var formatter = NSDateFormatter()
  formatter.dateFormat = &quot;yyyy-MM-dd'T'HH:mm:ss.SSS'Z'&quot;
  formatter.timeZone = NSTimeZone(forSecondsFromGMT: 0)
  println(formatter.stringFromDate(now))
  </code></pre>