Closed SalAldana closed 9 years ago
What do you mean by “getting just the time from this NSDate”? How were you doing that?
I was using a NSDateFormatter with the dateFormat set to "hh:mm a" and then creating a string using the date formatter and the date created from the ISO8601 library.
Can you show all of the code that creates, sets up, gives the date to, and gets the string from the NSDateFormatter?
Sorry for the delayed response, was tied up with a project. Here's the whole process that I was using to create the time string
//valueDict is a dictionary with the values sent back from the web service NSString dateString = [valueDict valueForKey:@"start_date"]; ISO8601DateFormatter formatter = [ISO8601DateFormatter new]; NSDate date = [formatter dateFromString:dateString]; NSDateFormatter timeFormatter = [NSDateFormatter new]; [timeFormatter setDateFormat:@"h:mm a"]; NSString *startTimeString = [timeFormatter stringFromDate:date];
What happens if you use @"h:mm aZZZ"
?
Tried it with @"h:mm aZZZ" and still got the same results. I'm sending a note to the team that created the Web Services as well to see if they changed something on there side since now all of the times that used to be correct are way off. It may be something on my side after all. Thanks.
Yeah, your original description sounds like ISO8601DateFormatter is returning the correct date for that string. The only thing left to investigate is whether NSDateFormatter is returning the correct string for that date, or the date itself is not the one you expected.
NSDateFomatter's result will depend on its calendar, locale, and time zone, so make sure those are right—and remember that they default to the user's settings, so if you've moved (or DST went on or off) since you last tried this, and you're not explicitly setting at least the time zone, that would cause the time string to change.
If it does turn out to be NSDateFormatter, please file a Radar.
After updating to iOS8 I've noticed that all of my dates are now coming back with the wrong date and time. For example this is the date string that I get from a web service "2015-01-15T18:30:00-08:00" and when I use:
ISO8601DateFormatter formatter = [ISO8601DateFormatter new]; NSDate date = [formatter dateFromString:inputString]; NSLog(@"%@", date);
The log shows the date as "2015-01-16 02:30:00 +0000" and then getting just the time from this NSDate gives me 6:30PM instead of 10:30AM (which is used to show before I moved to iOS8).
I can't tell if it's something on my side or with iOS8 and the library so I just figured i would put it here for now. Thanks.