当我使用Google日历的JSON输出读取事件的开始时间时,我会以“2009-03-05T10:46:25.245Z”的格式获得时间。如何在iPhone SDK中将其转换为含义完整日期和时间?
提前致谢。
答案 0 :(得分:0)
我认为这篇文章有你的答案:Nil NSDate when trying to get date from UTC string in zulu time
这似乎对我有用:
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);