How would I convert an NSString
like \"01/02/10\" (meaning 1st February 2010) into an NSDate
? And how could I turn the NSDat
Best practice is to build yourself a general class where you put all your general use methods, methods useful in almost all projects and there add the code suggested by @Pavan as:
+ (NSDate *)getDateOutOfString:(NSString *)passedString andDateFormat:(NSString *)dateFormat{
NSString *dateString = passedString;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:dateFormat];
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:dateString];
return dateFromString;
}
.. and so on for all other useful methods
By doing so you start building a clean reusable code for you app. Cheers!