In my iPhone app, I am trying to get the EEE MMM dd from a date string received by a web service.
For all dates where time is < 07:00, the NSDateFormatter returns a date off by 1 day. For example: Date to format: 2010-11-17T05:00:00, formatted date result: Tue Nov 16
Here's the code snippet:
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat: @"EEE MMM dd"];
NSDate *dateToFormat = [NSDate dateWithNaturalLanguageString:dateStringToFormat locale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]];
NSString *formattedDateString = [dateFormat stringFromDate:dateToFormat]; [dateFormat release];
What could be the problem?
Probably has something to do with time zones. You probably need to set an appropriate value for the timeZone property of your NSDateFormatter object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With