I have this piece of code:
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMMM d, YYYY"];
NSDate *formatDate = [dateFormat dateFromString:self.date];
NSLog(@"1-%@", self.date);
NSLog(@"2-%@", formatDate);
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:formatDate];
NSString *dateCal = [NSString stringWithFormat:@"%d/%d/%d", [components day], [components month], [components year]];
NSLog(@"3-%@", dateCal);
milage.date = dateCal;
The first NSLog returns:
1-March 23, 2012
The second:
2-2011-12-25 00:00:00 +0000
The third:
3-25/12/2011
Why does the date change when getting the date from the string and formatting it? I'm expecting the third NSLog (or dateCal) to equal 23/3/2012. I live in the UK so its not to do with the timezone..
Thanks,
Jack