I need to convert this string in to the date:
02-09-2011 20:54:18
I am trying the `dateFromString` method but every time it is returning (null), what NSDateFormatter should I use?, I have tried
`[formatter setDateFormat:@"yyyy-MM-dd"]` and `[formatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"]`.
Here is my code:
NSString *finalDate = @"02-09-2011 20:54:18";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd"];
NSDate *dateString = [formatter dateFromString:finalDate];
NSLog(@"%@",dateString);
Thanks.
I need to convert this string in to the date: 02-09-2011 20:54:18 I am
Share
You can convert a NSString containing a date to a NSDate using the NSDateFormatter with the following code: