How can I initialize a date to NSDate?

nsdate, objective-c

Solution

What you need to do is something like this:

NSDateFormatter *mmddccyy = [[NSDateFormatter alloc] init];
mmddccyy.timeStyle = NSDateFormatterNoStyle;
mmddccyy.dateFormat = @"MM/dd/yyyy";
NSDate *d = [mmddccyy dateFromString:@"12/11/2005"];
NSLog(@"%@", d);

Problem

I want to give, for example, `12/11/2005` in the format of `mm/dd/yyyy`. Can I initialize `12/11/2005` to `NSDate` directly? Any help? It gives a warning and crashes when I declare it as: ``` NSDate *then = [NSDate dateWithNaturalLanguageString:02/11/2009 locale:nil]; ```

Original source