Alosyius
Alosyius

Reputation: 9111

iOS date format conversion?

I am trying to convert this format:

2013-10-29T07:32:02.000Z

Into:

yyyy-MM-dd HH:mm:ss ZZZ

Have tried:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE MMM dd HH:mm:ss ZZZ yyyy"];
NSDate *date  = [dateFormatter dateFromString:sDate];

// Convert to new Date Format
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];
NSString *newDate = [dateFormatter stringFromDate:date]; 

But cannot get it to work, any ideas?

Upvotes: 0

Views: 221

Answers (1)

neilco
neilco

Reputation: 8012

Your initial date format is incorrect. 2013-10-29T07:32:02.000Z has a format of yyyy-MM-dd'T'HH:mm:ss.SSS'Z'.

Upvotes: 3

Related Questions