title: Convert ISO 8601 to NSDate
body: <p>I have a timestamp coming from server that looks like this: </p>
  
  <pre><code>2013-04-18T08:49:58.157+0000
  </code></pre>
  
  <p>I've tried removing the colons, I've tried all of these: </p>
  
  <p><a href="https://stackoverflow.com/questions/5185230/converting-an-iso-8601-timestamp-into-an-nsdate-how-does-one-deal-with-the-utc">Converting an ISO 8601 timestamp into an NSDate: How does one deal with the UTC time offset?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/7925038/why-nsdateformatter-can-not-parse-date-from-iso-8601-format">Why NSDateFormatter can not parse date from ISO 8601 format</a></p>
  
  <p>Here is where I am at: </p>
  
  <pre><code>+ (NSDate *)dateUsingStringFromAPI:(NSString *)dateString {
  
  
      NSDateFormatter *dateFormatter;
      dateFormatter = [[NSDateFormatter alloc] init];
  
      //@"yyyy-MM-dd'T'HH:mm:ss'Z'" - doesn't work
      //@"yyyy-MM-dd'T'HH:mm:ssZZZ" - doesn't work
      //@"yyyy-MM-dd'T'HH:mm:sss" - doesn't work 
  
      [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
      [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
  
      // NSDateFormatter does not like ISO 8601 so strip the milliseconds and timezone
      dateString = [dateString substringWithRange:NSMakeRange(0, [dateString length]-5)];
  
      return [dateFormatter dateFromString:dateString];
  }
  </code></pre>
  
  <p>One of my biggest questions is, is the date format I have above really ISO 8601? All the examples I have seen from people the formats of each are slightly different. Some have <code>...157-0000</code>, others don't have anything at the end. </p>