The NSDateFormatter class is super handy for scanning incoming text dates in order to create a NSDate object, so that you can then use for other date manipulation.
As handy as it is, it is not as well documented as one would hope.
As a bit of a teaser, I’ll list a version of a NSDateFormatter helper function that will take dates from the Twitter API and convert them into NSDate objects. I will flesh out the details behind the function in a post to come Thursday or Friday.
NSDateFormatter Helper:
-(NSDate*)dateFromTwitter:(NSString*)str {
static NSDateFormatter* sTwitter = nil;
if (str == nil) {
NSDate * today = [[[NSDate alloc] init] autorelease];
return today;
}
if (!sTwitter) {
sTwitter = [[NSDateFormatter alloc] init];
[sTwitter setTimeStyle:NSDateFormatterFullStyle];
[sTwitter setFormatterBehavior:NSDateFormatterBehavior10_4];
[sTwitter setDateFormat:@”EEE LLL dd HH:mm:ss Z yyyy”];
}
return [sTwitter dateFromString:str];
}
For date_created field of search result I use: @”EEE, d MMM yyyy HH:mm:ss Z”
LikeLike