Reputation: 541
Here's the code in question:
// configure created_at date for display
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
NSLog(@"formattedDate=%@",dateFormatter.dateFormat);
NSLog(@"created_at=%@",notice.created_at);
NSString *createdDateStr = [dateFormatter stringFromDate:notice.created_at];
NSLog(@"createdDateStr=%@",createdDateStr);
self.labelCreated.text=createdDateStr;
And here's what's coming out per NSLog:
2014-06-29 12:06:48.945 [3589:60b] formattedDate=MMM d, y
2014-06-29 12:06:48.947 [3589:60b] created_at=2013-02-22T08:49:52Z
2014-06-29 12:06:48.948 [3589:60b] createdDateStr=(null)
This looks a lot more complicated that it needs to be, but I was following examples from the Mac Developers Library (iOS 7.x, Xcode 5.x) Any guidance would be greatly appreciated.
Upvotes: 0
Views: 67
Reputation: 15015
Your created_at date format is different. So first you need to set the dateformat accordingly as created_at dateformat like that below:-
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
Upvotes: 1
Reputation: 3120
Please consider, if you are converting date format from string, you should write the format exactly like in your string with spaces etc. Other ways date format will return null
Upvotes: 1