Google JSON API output for iPhone Time zone
When I read the start time for an event using the JSON output for Google calendar I get the time in this format "2009-03-05T10:46:25.245Z". How can I convert this to meaning full date and 开发者_StackOverflow社区time in iPhone SDK?
Thanks in advance.
I think this post has your answer: Nil NSDate when trying to get date from UTC string in zulu time
This seems to work for me:
NSString *timeValue = @"2009-03-05T10:46:25.245Z";
NSDateFormatter* df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
NSDate* date = [df dateFromString:[timeValue stringByReplacingOccurrencesOfString:@"Z" withString:@"-0000"]];
NSLog(@"The date is: %@",date);
精彩评论