您能否帮助我进行这种转换 我有NSString date @“2012年8月7日7:21:09 PM” 而且我需要在输出中有这样的字符串: “在下午7时21分,2月8日” 我试图使用dateFormatter不同日期的模式,但它总是返回我null..I真的不understandd哪里我做错了:(将NSString日期转换为NSDate或特定的字符串
NSString *dateString = newsItem.Date;//Which is equal to @"2/8/2012 7:21:09 PM"
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"mm/dd/yyyy hh:mm:ss"];//I'm sure that this patternt is wrong but have no idea how to write the right one
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:dateString];
[dateFormatter release];
NSLog(@"date:%@", dateFromString);
'NSDateFormatter'是此作业的正确工具。如果它总是返回null,那意味着你给它的格式字符串与实际的日期格式不匹配。你必须具体展示你想要告诉你什么是错的... – 2012-02-14 17:27:31
发布你使用dateFormatter尝试过的代码。 – bschultz 2012-02-14 17:27:32