0

I often need to do this to create NSDate objects to compare against in tests—to make sure a timestamp specified in millis past the Epoch UTC in a JSON file is parsed correctly, for example.

What is the correct way to do this in Objective-C with the least boilerplate?

Robert Atkins
  • 23,528
  • 15
  • 68
  • 97
  • Thanks driveby downvoter, that was really helpful! The point was not that the answer is necessarily difficult, but that the obvious answer seems to me like way too much boilerplate and whether NSDateFormatter supports ISO8601 out-of-the-box is unclear. – Robert Atkins Jan 10 '14 at 11:21

1 Answers1

0

The "obvious" version is three lines:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm"];
NSDate *date = [dateFormatter dateFromString:@"1997-07-27T09:00:00Z"];
Robert Atkins
  • 23,528
  • 15
  • 68
  • 97