Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Formatting Dates with NSDateFormatter

This is my code, in tableView.m i have:
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ - %@", blogPost.author, [blogPost formattedDate]]; return cell;

I am getting null for my dates?

blogPost.m code below. -(NSString *) formattedDate; { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSDate *tempDate = [dateFormatter dateFromString:self.date];

[dateFormatter setDateFormat:@"EE MMM, dd"];
return [dateFormatter stringFromDate:tempDate];


2 Answers

Patrick Donahue
Patrick Donahue
9,523 Points
 -(NSString *) formattedDate; { NSDateFormatter *dateFormatter = 

Remove the semi colon after formatted date.

solved it was NSDictionary i did not have - bp.date = [blogPostDictionary objectForKey:@"date"]; Thats why i was getting null. Sorry about the way the code pasted in above.