Dev Dev - 1 month ago 6
iOS Question

iOS : Date format - 20-Sep-2012

I want to display the date in the format "20-Sep-2012" from the string "2012-11-22 10:19:04". How can i do this? Is there any in-built method for iOS?

Answer
NSString *myString = @"2012-11-22 10:19:04";
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";     
NSDate *yourDate = [dateFormatter dateFromString:myString];
dateFormatter.dateFormat = @"dd-MMM-yyyy";
NSLog(@"%@",[dateFormatter stringFromDate:yourDate]);

your log will print like this. 22-Nov-2012