In my app I download some data as JSON from an API which contains an entry with local time:
"local_date" : "2015-07-08T13:18:14+02:00"
The JSON data are parsed into an NSDictionary* information:
NSDateFormatter* dateFormatter= [NSDateFormatter new];
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZ";
NSDate *date = [self.dateFormatter dateFromString:information[@"local_date"]];
The date is now correctly set in UTC (which i need for some computations) but to display the local data in the user interface i need to display the date in the correct time zone.
My Question ist:
How can i extract the NSTimeZone from my string? I am looking for something like NSTimeZone* timeZone = [NSTimeZone parseFromString:@"+02:00"];
I've read the documentation of NSDateFormatter, NSCalendar and NSTimeZone but didn't find out how to get the timezone from a string like mine.
Thanks in advance!
parseFromStringmethod, what answer would you consider to be correct? - Tom Harrington