我正在使用以下代码尝试在表格单元格中显示时间。
TimeSlot *timeSlot = [timeSlots objectAtIndex:indexPath.row];
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
[timeFormat setDateFormat:@"HH:mm:ss"];
NSLog(@"Time: %@", timeSlot.time);
NSDate *mydate = timeSlot.time;
NSLog(@"Time: %@", mydate);
NSString *theTime = [timeFormat stringFromDate:mydate];
NSLog(@"Time: %@", theTime);
日志输出是这样的:
- 2010-04-14 10:23:54.626 MyApp[1080:207] 时间:2010-04-14T10:23:54
- 2010-04-14 10:23:54.627 MyApp[1080:207] 时间:2010-04-14T10:23:54
- 2010-04-14 10:23:54.627 MyApp[1080:207] 时间:(空)
我是为 iPhone 开发的新手,因为它全部编译时没有错误或警告,我不知道为什么我在日志中得到 NULL。这段代码有什么问题吗?
谢谢
更多信息
我完全使用了您的答案 lugte098 中的代码来检查并且我得到了日期,这让我相信我的 TimeSlot 类不能在它的 NSDate 属性中正确设置日期。所以我的问题变成了 - 我如何从 XML 设置 NSDate 属性?
我有这个代码(缩写):
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *) string {
if ([currentElement isEqualToString:@"Time"]) {
currentTimeSlot.time = string
}
}
谢谢