【发布时间】:2013-05-10 06:01:11
【问题描述】:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
id <NSFetchedResultsSectionInfo> theSection = [[self.fetchedResultsController sections] objectAtIndex:section];
//return [[[theSection name]componentsSeparatedByString:@"+"]objectAtIndex:0];
return [NSDateFormatter localizedStringFromDate:[NSDate dateWithTimeIntervalSince1970:[theSection name]] dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterNoStyle];
}
我想使用NSDateFormatter 来显示从核心数据中获取的日期时间并根据需要显示。
更新 1
NSDateFormatter *f = [[NSDateFormatter alloc]init];
[f setDateFormat:@"dd:mm:yy hh:mm"];
NSDate *d = [f dateFromString:[theSection name]];
return [f stringFromDate:d];
这也不起作用:(
更新 2
NSLog(@"TEST=>%@",[theSection name]);
显示2013-05-09 11:58:28 +0000,但在数据库中它的存储是这样的
389773826.504289
【问题讨论】:
-
也许您应该告诉日期所需的格式如何。如果不是,那就很难知道了
-
@pdrcabrod mm:dd:yy hh:mm:ss
-
你使用时发生了什么:
[NSDateFormatter localizedStringFromDate:[NSDate dateWithTimeIntervalSince1970:[theSection name]] dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterNoStyle];? -
@pdrcabrod 在 NSLog 中获取 (null) 并在表中获取空标题,也请查看我的问题中的更新但同样的问题。注释中的代码显示日期时间,但不是必需的格式。
标签: ios objective-c core-data nsdate nsdateformatter