I have a date January 2012. I need a NSDateFormatter
for such date.
Here's my code...
//Array of Date-formatter Strings
NSArray *dateFormatterList = [
NSArray arrayWithObjects:
@"yyyy-MM-dd'T'HH:mm:ss'Z'",
@"yyyy-MM-dd'T'HH:mm:ssZ",
@"yyyy-MM-dd'T'HH:mm:ss", @"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
@"yyyy-MM-dd'T'HH:mm:ss.SSSZ", @"yyyy-MM-dd HH:mm:ss",
@"MM/dd/yyyy HH:mm:ss", @"MM/dd/yyyy'T'HH:mm:ss.SSS'Z'",
@"MM/dd/yyyy'T'HH:mm:ss.SSSZ", @"MM/dd/yyyy'T'HH:mm:ss.SSS",
@"MM/dd/yyyy'T'HH:mm:ssZ", @"MM/dd/yyyy'T'HH:mm:ss",
@"yyyy:MM:dd HH:mm:ss", @"yyyyMMdd", @"dd-MM-yyyy",
@"dd/MM/yyyy", @"yyyy-MM-dd", @"yyyy/MM/dd",
@"dd MMMM yyyy", @"MMddyyyy", @"MM/dd/yyyy",
@"MM-dd-yyyy",@"d'st' MMMM yyyy",
@"d'nd' MMMM yyyy", @"d'rd' MMMM yyyy",
@"d'th' MMMM yyyy", @"d'st' MMM yyyy",
@"d'nd' MMM yyyy", @"d'rd' MMM yyyy",
@"d'th' MMM yyyy", @"d'st' MMMM",
@"d'nd' MMMM", @"d'rd' MMMM",
@"d'th' MMMM", @"d'st' MMM",
@"d'nd' MMM", @"d'rd' MMM",
@"d'th' MMM",@"MMMM yyyy",nil];
NSString *targetDateFormatString = @"dd-MM-yyyy";
count++;
if (resultString) {
for (NSString *dateFormatterString in dateFormatterList) {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:dateFormatterString];
NSDate *originalDate = [dateFormatter dateFromString:resultString];
if (originalDate) {
[dateFormatter setDateFormat:targetDateFormatString];
myDateString = [dateFormatter stringFromDate:originalDate];
[finalDateArray addObject:myDateString];
//NSLog(@"Converted date String is %@", myDateString);
break;
}
}
}