我不能讓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