I am trying this since last two hours and finaly left it out for you guys 😛
I need to convert this String Mon, 14 May 2012, 12:00:55 +0200
into Date dd/mm/yyyy hh:ss format..
Any kind of help towards the goal will be really appreciated.
What I have tried
I have tried using NSDateFormatter but I am unable to figure out the exact format of the above date.
This [dateFormatter setDateFormat:@"EEEddMM,yyyy HH:mm:ss"]; is how I have tried and many other formats too
Eg:
NSString *finalDate = @"Tue, 29 May 2012, 14:24:56 +0200";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEEddMM,yyyy HH:mm:ss"];
NSDate *date = [dateFormatter dateFromString:finalDate];
Here the date alwasys comes as nil
The most important part of date formatting is often forgotten, tell the
NSDateFormatterthe input language:I’ve checked the output:
date: 2012-05-14 10:00:55 +0000Be aware that the
HHin the date formatter is for24hr.Now I would suggest not to use a fixed output scheme, but use one of the
NSDateFormatterStyle:Which in american english will output:
5/14/12 12:00 PMThis code is valid for
ARCif you are not usingARCaddautoreleaseto theNSLocaleand release theNSDateFormatterafter you are done with it.