I have a string that I want to parse the time from:
NSString *longdate = @\"Mar 27, 2011 8:38:38 PM\";
I want to parse this date and output jus
Found the problem. Had nothing to do with timezones and everything to do with using the wrong formatting codes for the date formatter.
[inFormat setDateFormat:@"MMM dd, yyyy HH:mm:ss aaa"];
should be:
[inFormat setDateFormat:@"MMM dd, yyyy h:mm:ss aaa"];
Likewise, outFormat's dateformat should be:
[outFormat setDateFormat:@"h:mm aaa"];
After this adjustment everything works fine even w/o any TimeZone adjustments.
You've got your timezones messed up. IIRC, NSDateFormatter
(by default) will parse stuff in the UTC timezone (+000), but dates are NSLog
ged in your current timezone. Or something like that.
Anyway, check your timezones.
As Dave said, check your time zones. You can tell the date formatter to use your current time zone as well:
[outFormat setTimeZone:[NSTimeZone localTimeZone]];