I have string with value 01012016
which i want to show to user like 01-01-2016
. For this, i am using the below code
-(NSString *)dateToFormatedDate:(NSString *)dateStr {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[dateFormatter setDateFormat:@"MM-dd-yyyy"];
NSDate *date = [dateFormatter dateFromString:dateStr];
NSLog(@"date is %@", [dateFormatter stringFromDate:date]);
return [dateFormatter stringFromDate:date];
}
But this method is always returning nil. I have tried on simulator and device both. I am not able to figure it out what i did wrong here