这是我的JSON
{
0 = "2011-11-11";
1 = "2011-12-31";
endDate = "2011-12-31";
startDate = "2011-11-11";
}
我的代码是
NSString *dateString = [jsonDict objectForKey:@"0"]
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EE, d LLLL yyyy HH:mm:ss Z"];
NSDate *date = [dateFormat dateFromString:dateString];
[dateFormat release];
但是这段代码无效。
如何将JSON数据转换为日期格式?
答案 0 :(得分:3)
您在setDateFormat
中使用了错误的格式。你应该使用:
NSString *dateString = [jsonDict objectForKey:@"0"]
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd"];
NSDate *date = [dateFormat dateFromString:dateString];
[dateFormat release];