Reputation: 1847
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
NSDate *date1 =[[NSDate alloc] init];
date1 = [dateFormat dateFromString:@"11-nov-2013"];
NSLog(@"date is %@",date1); // it returns null
self.datePicker.date = date1;
[dateFormat release];
Upvotes: 0
Views: 74
Reputation: 13713
You need to set the date format as well :
[dateFormat setDateFormat:@"dd-MM-yyyy"];
Upvotes: 0
Reputation: 9836
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"dd-MMM-yyyy"];
NSDate *myDate = [formatter dateFromString:@"11-nov-2013"];
NSLog(@"date is %@",myDate);
Upvotes: 1
Reputation: 4671
Set date format to
[dateFormat setDateFormat:@"dd-MM-yyyy"];
Upvotes: 0