Take the 2-minute tour ×

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, 2012 12:00:00 AM

Is there an easy way to do this on obj-c , or i must parse everything hardcore , and make my own function for this? If yes , any ideas how this would look like , cause i am new on iOS. Thank you very much for reading my post :D

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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];
share|improve this answer

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];
share|improve this answer

Your Answer


