当我打印 sourceDate 的日志时,我得到空值。 它将给出 NULL 值。
代码是:
NSMutableString * orignalStr = [[NSMutableString alloc] init];
[orignalStr appendString:date];
[orignalStr replaceOccurrencesOfString:@"T"
withString:@" "
options:NSCaseInsensitiveSearch
range:NSMakeRange(0, 15)];
NSLog(@"The orignalString is =%@ ",orignalStr);
NSDateFormatter* dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss zzz "];
NSDate *sourceDate =[dateFormatter dateFromString:orignalStr];
NSLog(@"The sourceDate is =%@ ",sourceDate);
请帮帮我...
最佳答案
尝试使用此日期格式字符串:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"
,而不替换出现的 @“T”
。
评论后编辑
您有一个字符串,例如:“2011-07-19 GMT:10:00”,格式字符串应为 @"yyyy'-'MM'-'dd' GMT:'HH':'ss “
。
关于objective-c - 返回 NULL 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6772468/