几乎尝试了一切并获得null,
我作为参数'NSString'传递的格式:WED 13-11-2013
-(NSDate*)stringToDate:(NSString*)dateString{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
// [dateFormat setDateFormat:@"EE, d-LLLL-yyyy HH:mm:ss Z"];
// [dateFormat setDateFormat:@"EE, dd-MM-yyyy"];
[dateFormat setDateFormat:@"EEE, dd-MM-yyyy"];
// NSString *str = [dateString stringByAppendingString:@" 09:00:00 +0000"];
// NSDate *date = [dateFormat dateFromString:dateString];
NSDate *date = [dateFormat dateFromString:dateString];
return date;
}
答案 0 :(得分:4)
嗨试试这对我有用:
-(NSDate*)stringToDate:(NSString*)dateString{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"EEE dd-MM-yyyy ";
[dateFormatter setLocale:[NSLocale currentLocale]];
NSDate *date = [dateFormatter dateFromString:dateString];
return date
}