I am in the process of converting a NSString to an NSDate and running into an issue where the year is wrong in the final conversion.
My input date is 2013-05-27 03:38:20 +0000
(listed as lastEntry.date in the code below)
My Conversion code is as follows:
//Convert String to NSDate
NSDateFormatter *originalDateFormat = [[NSDateFormatter alloc] init];
[originalDateFormat setDateFormat:@"YYYY-MM-dd hh:mm:ss Z"];
[originalDateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
NSDate *originalEndDate = [originalDateFormat dateFromString:lastEntry.date];
NSLog(@"Converted End Date = %@", [originalDateFormat stringFromDate:originalEndDate]);
The Final Output I get is: Converted End Date = 2012-05-27 03:38:20 +0000
I am not sure why I am losing a year during this conversion. In all my research so far it seems the hardest part of this conversion process is making sure the format is correct, and since my output date is in the right format I feel there is another issue else where. Is there something that I am missing or doing wrong?