【发布时间】:2015-04-20 10:59:26
【问题描述】:
- (void)viewDidLoad {
[super viewDidLoad];
self.dateTimeFormate = [[NSDateFormatter alloc] init];
self.dateTimeFormate.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
[self.dateTimeFormate setDateFormat:@"mm-dd-YYYY hh:mm"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.textLabel.text = [[self.arrFeeds objectAtIndex:indexPath.row] objectForKey:@"title"];
NSString *strPubDate = [[self.arrFeeds objectAtIndex:indexPath.row] objectForKey:@"pubDate"];
NSString *strPubDateTrim = [strPubDate stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *strCreator = [[self.arrFeeds objectAtIndex:indexPath.row] objectForKey:@"dc:creator"];
NSString *strCreatorTrim = [strCreator stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSDate *dateTime = [self.dateTimeFormate dateFromString:strPubDateTrim];
NSString *strPubDateTime = [self.dateTimeFormate stringFromDate:dateTime];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ - %@",strPubDateTime,strCreatorTrim];
return cell;
}
}
【问题讨论】:
-
字符串strPubDateTrim的值是多少?
-
您的输入字符串不是 NSDateFormatterShortStyle 类型
-
suhit ,如上所述。 “4 月 20 日星期一……”
标签: ios objective-c nsdateformatter