2012-11-08 41 views
0

我想從NSDate中獲取相對天數到我的UITableViewCell中。NSDate問題 - 格式化到相對天

我有這樣的代碼:

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
[dateFormat setDateFormat: @"yyyy-MM-dd HH:mm:ss"]; 

產生這樣的:

enter image description here

現在,我的理解是,如果我使用[dateFormat setDoesRelativeDateFormatting:YES]; 日期應顯示在天名字例如:昨天,星期一等

然而,當我把那條線 - detailText線根本不顯示。

NSDate *dateTmp; 
dateTmp = [[self.Notes objectAtIndex:indexPath.row ]objectForKey:@"CDate"]; 
cell.detailTextLabel.text = [dateFormat stringFromDate: dateTmp]; 

任何想法??

+2

看看這裏: http://stackoverflow.com/questions/4937230/relative-string-from-nsdate – NSAddict

回答