使用类似于以下内容的方法将 NSDate(在您的字典中)转换为 NSString,但请选择您需要的正确日期和时间样式:
self.lblTheDate.text = [NSDateFormatter localizedStringFromDate:[self.item valueForKey:@"MyDate"] dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterNoStyle]
日期和时间样式有多种选择:
NSDateFormatterNoStyle : Specifies no style,
NSDateFormatterShortStyle : Specifies a short style, typically numeric only, such as “11/23/37” or “3:30pm”,
NSDateFormatterMediumStyle : Specifies a medium style, typically with abbreviated text, such as “Nov 23, 1937”,
NSDateFormatterLongStyle : Specifies a long style, typically with full text, such as “November 23, 1937” or “3:30:32pm”,
NSDateFormatterFullStyle : Specifies a full style with complete details, such as “Tuesday, April 12, 1952 AD” or “3:30:42pm PST”
请注意,这些日期和时间样式的格式并不准确,因为它们取决于区域设置、用户首选项设置和操作系统版本。
类参考:
NSDateFormatter