返回 NULL 值
当我打印 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);
请帮助我...
I get the null value when i print the log for sourceDate.
it will give NULL value.
The code is:
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);
plz help me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用此日期格式字符串:
@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"
,而不替换出现的@ “T”
。评论后编辑
您得到的字符串如下:“2011-07-19 GMT:10:00”,格式字符串应为
@"yyyy'-'MM'-'dd' GMT :'HH':'ss"
。Try using this date format string :
@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"
, without replacing occurences of@"T"
.EDIT after comment
You got a string like : "2011-07-19 GMT:10:00", the format string should be
@"yyyy'-'MM'-'dd' GMT:'HH':'ss"
.