So, it turns out NSDateFormatter, a formidable class for converting and manipulating date formats in iOS development, met its match with the ISO8601 date format that I was getting from a rails based API. Or at least, that's what I found. So here's how I coped with it:

The json:

"start_date": " "2014-10-26T21:00:00.000+00:00"

Turns out, NSDateFormatter can't parse this.

I did quite a bit of digging around and in the end, my friend and mentor @HunterBridges pointed me in the direction of this nifty little library on GitHub

https://github.com/boredzo/iso-8601-date-formatter

It even has a nice little xkcd comic in the README, so definitely work checking out, just for that.

I downloaded and extracted just the header and implementation files "ISO8601DateFormatter" and included them in my model class. 

#import "ISO8601DateFormatter.h"

Then, in the implementation where I was initialising my model instance from the API response dictionary:

 

NSString *datestr = [result objectForKeyNotNull:@"start_at"];
NSLog(@"Date String: %@", datestr);
ISO8601DateFormatter *dateFormat = [[ISO8601DateFormatter alloc] init];
NSDate *date = [dateFormat dateFromString:datestr];
NSLog(@"Formatted Date String: %@", [dateFormat stringFromDate:date]);

 

Note "objectForKeyNotNull:" method is a convenience method for making sure the result doesn't contain a null value.

So, I grab the original date format from the web service response and save it as an NSString.

I then alloc and init the new ISO8601 class as dateFormat variable. Then I create a new NSDate object and call dateFromString on my dateFormat variable, passing it the original dateStr variable as a parameter.

And that's it. Later on, I create a normal NSDateFormatter to parse the new date object and get just the time in HH-mm format, which is what I actually wanted for the app feature I was building.

osi