我一直在努力弄清楚为什么dateFromString method
会返回错误的日期。
以下是代码:
NSDate *secondDate = [df dateFromString:@"12.31.9999"];
它的输出如下:
1999-12-31 07:00:00 +0000
这个方法有问题吗?这同样适用于iOS5。问题仅出现在iOS6中。
答案 0 :(得分:3)
试试这个。希望这能解决你的问题
- (NSString *) convertedDate : (NSString *) dateStr {
NSString *finalDate = dateStr;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy/MM/dd"];//In which formate you are date is passing
NSDate *date = [dateFormatter dateFromString:finalDate];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/yyyy"];// in which formate date you want
NSString *dateString = [formatter stringFromDate:date];
return dateString;
}