返回NULL值

时间:2011-07-21 07:08:24

标签: objective-c ios nsdate

当我打印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);

请帮助我...

1 个答案:

答案 0 :(得分:1)

尝试使用此日期格式字符串:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'",而不替换@"T"的出现。

评论后编辑

你有一个字符串:“2011-07-19 GMT:10:00”,格式字符串应为@"yyyy'-'MM'-'dd' GMT:'HH':'ss"