I have a string is @"Tuesday, January 01, 2013", and I use code as below to convert it to date, but I only get nil, does anyone tell me why?
Code:
+ (NSDate *)dateFromString:(NSString *)string withFormat:(NSString *)format {
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
[inputFormatter setDateFormat:format];
NSDate *date = [inputFormatter dateFromString:string];
return date;
}
NSString *str = @"Tuesday, January 01, 2013";
NSDate *date = [NSDate dateFromString:str withFormat:@"EEEE, MMMM dd, yyyy"];