我是 Objective-c 的新手,我遇到了日期格式器的第一个问题。我正在解析提要并获得文章的日期。
格式为:Tue, 31 Mar 2015 10:52:33 。我想将此刺痛转换为日期。我尝试了多种方法,但总是得到这个:
NSDate *articleDate = [NSDate dateFromInternetDateTimeString:dataArticol formatHintateFormatHintRFC3339];
NSDate *newData=[NSDate dateFromInternetDateTimeString:dataArticol formatHint"EEE , dd-MM-yyyy'T'HH:mm:ss.SSSZ"];
结果:
2015-03-31 14:54:40.744 FluxRSS[6358:1052102] Could not parse RFC822 date: "Tue, 31 Mar 2015 10:52:33
" Possible invalid format.
或者如果我喜欢:
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat"EEE , dd-MM-yyyy'T'HH:mm:ss.SSSZ"];
[formatter setLenient:YES];
NSString* buggeredTime = [[dataArticol substringToIndex:26] stringByAppendingString:[dataArticol substringFromIndex:27]];
NSDate* dueDate = [formatter dateFromString:buggeredTime];
[formatter setDateFormat"'Time Due: 'hh:mm a MM/dd/yy"];
NSString* dateString = [formatter stringFromDate:dueDate];
dueData 为 nil 。任何人都可以帮助我吗?
使用它正在工作的代码..
NSString *string=@"Tue, 31 Mar 2015 10:52:33";
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat"EEE, dd MM yyyy HH:mm:ss"];
NSDate *date=[formatter dateFromString:string];
关于ios - 无法解析 RFC822 日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29368261/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |