我不能让NSDate为我的生活工作,即使我认为我已经扫描堆栈溢出的问题,所以帮助将不胜感激。字符串NSDate问题
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *publishedText = [NSString stringWithFormat:@"%@", feedLocal.published];
cell.publishedLabel.text = publishedText;
return cell;
}
给我的字符串:
2013-05-08 18:09:37 +0000
这我想变成:五月 8,2013 6:45 PM
我已经尝试使用:
NSString *publishedText = [NSString stringWithFormat:@"%@", feedLocal.published];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSSSSS"];
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [df dateFromString:publishedText];
cell.publishedLabel.text = dateFromString;
但它不起作用,并显示指针类型不兼容的警告(NSString
到NSDate_strong
)。谢谢您的帮助!
这很愚蠢:'NSDate * dateFromString = [[NSDate alloc] init];'。为什么要初始化一个变量,然后在下一个语句中覆盖该值? – 2013-05-09 22:46:39
是的,我不认为这是正确的。 @rmaddy给了我一个完美的答案,帮助我完成下面的工作 – Realinstomp 2013-05-09 23:06:34
@热舔酷评论bro – 2014-07-25 16:03:53