The date you get back from twitter is in this format Fri Aug 07 12:40:04 +0000 2009
. I am able to assign the value to a NSDate without issue. However, when I attempt to use NSDateFormatter, I get a nil returned to me. What am I missing?
NSDate *createdAt = [messageData objectForKey:@"created_at"];
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"M/d/yy HH:mm"];
NSString *dateString = [format stringFromDate:createdAt];
label.text = dateString;
i had the same question, and i could not resolve it with the current above answers. so here is what worked for me:
NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
//Wed Dec 01 17:08:03 +0000 2010
[df setDateFormat:@"eee, dd MMM yyyy HH:mm:ss ZZZZ"];
NSDate *date = [df dateFromString:[[tweets objectAtIndex: storyIndex] objectForKey: TWITTER_CREATED_AT_JSON_KEY]];
[df setDateFormat:@"eee MMM dd yyyy"];
NSString *dateStr = [df stringFromDate:date];
where tweets
is an NSMutableArray
filled with NSDictionary
objects, storyIndex
being the row int value (in the tableview), and TWITTER_CREATED_AT_JSON_KEY
being a constant NSString
with value created_at
. use the dateStr
wherever you wish to display the date
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With