I have some dates in this format :
2012-06-26 12:00:00 +0000
and what i want to do is convert them in this format :
Jun 26,
First, you should convert your string (with a NSDateFormatter ) in a NSDate and than convert it back to a NSString (still with the same NSDateFormatter) with the target format.
Here is an example of a NSDateFormatter :
NSString *dateString = @"2013-04-01T22:00:00Z";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
[dateFormatter setTimeZone:[NSTimeZone defaultTimeZone];
NSDate *theDate = [dateFormatter dateFromString:dateString];
To convert from 1 string to the other use the following
NSString *inputString = @"2012-06-26 12:00:00 +0000";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd hh:mm:ss z"];//input
NSDate *date = [formatter dateFromString:inputString];
[formatter setDateFormat:@"MMM dd, yyyy hh:mm:ss a"];
NSString *outputString = [formatter stringFromDate:date];
NSLog(@"output : %@",outputString);