You will need to create an NSDateFormatter and then set its dateFormat according to the first date, for example:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
This will set the date format to find out your date string. Then you can get the NSDate object using
NSDate *myDate = [dateFormatter dateFromString:myDateString];
This gives you the complete NSDate object representing this date. Now you need to reformat the date and return it back to the string, so set the date format in your formatter to a new format and get a new string representation of the returned date:
[dateFormatter setDateFormat:@"dd/MM\nyyyy"]; NSString *newlyFormattedDateString = [dateFormatter stringFromDate:myDate]; [dateFormatter release], dateFormatter = nil;
And voila! You have a new date :)
source share