开发者

Google JSON API output for iPhone Time zone

开发者 https://www.devze.com 2023-02-01 13:33 出处:网络
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 开发者_Sta

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号