I am trying to format a date object and I am noticing on the string I am passing in; 6 hours is being added to my time. This seems to be associating my date time object to GMT.
My code:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd h:mm:ss a"];
[formatter setTimeZone:[NSTimeZone systemTimeZone]];
NSDate *date = [formatter dateFromString:@"2012-02-01 03:38:12 AM"];
NSLog(@"%@", date);
The result is:
2012-02-01 09:38:12 +0000
I have tried this with and without the setTimeZone and it does not matter. Any ideas on why this is displaying as GMT time?
Thanks,
Flea
The date that your formatter creates is not associated with any timezone, but the
descriptionmethod ofNSDate(which is whatNSLoguses for the output) converts any date to UTC. You would have to use another (or the same) date formatter’sstringFromDate:method to print it with a different time zone.