convert RSS pubDate to SQLite date format iPhonne
I'm trying to build a RSS reader, but I'm having trouble with saving the date to CoreData.
NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy-MM-dd"]; NSDate *dt = [df dateFromString: [article valueForKey:@"pubDate"]]; [df release];
When I save everything, the date field in the database is null.
Please help!
pubDate
is an RFC822 format field. The date format you're giving to the NSDateFormatter
seems inappropiate.
Have a look at this question for parsing RFC822 on an iPhone.
Log out the date and make sure you are saving the core data object correctly. You can try the following save for a detailed error message, if any.
NSError* error;
if (![managedObjectContext save:&error]) {
NSLog(@"Failed to save to data store: %@", [error localizedDescription]);
NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
if(detailedErrors != nil && [detailedErrors count] > 0) {
for(NSError* detailedError in detailedErrors) {
NSLog(@" DetailedError: %@", [detailedError userInfo]);
}
} else
NSLog(@" %@", [error userInfo]);
}
链接地址: http://www.djcxy.com/p/35160.html