I have an NSDateformatter that is not working correctly. I got my date as a string like this.
2013-02-20 00:00:00
And I need to return it as an NSDate like this
2013-02-20
What I’ve got at the moment is this.
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
[dateFormat setDateFormat:@"yyyy-MM-dd"];
[dateFormat dateFromString:dateString]
But this is not working.
Any help ?
if you have more than on date to parse, it could be worthy to create one input and one output date formatter
result
as NSDateFormatter are expensive to create, you should either store them in a singleton or declare them static to create them once for that method.
A date has no format, it is just a point in time. you will have to creta a string with the desired format where needed.