【发布时间】:2021-10-04 07:47:02
【问题描述】:
将字符串转换为日期总是返回 nil。这里一定漏掉了什么:
NSHTTPURLResponse *httpResponse = nil;
[NSURLConnection sendSynchronousRequest:request returningResponse:&httpResponse error:nil];
NSString *dateString = [[httpResponse allHeaderFields] objectForKey:@"Date"];
DebugLog(@" *** GOOGLE DATE: %@ ****",dateString);
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[NSDateFormatter dateFormatFromTemplate:@"E MMM d yyyy" options:0 locale:locale];
NSDate *currentDateFromWeb = [dateFormat dateFromString:dateString];
字符串正确打印为:Wed, 28 Jul 2021 13:51:16 GMT
尝试了多种日期格式器样式,还是nil
【问题讨论】:
标签: ios objective-c nsdate