NSDateFormatter 有自己的想法
我有以下日期格式化程序代码
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-ddThh:mm:ss"];
NSDate *result = nil;
NSRange range = NSMakeRange(0, 10);
NSError *error = nil;
[df getObjectValue:&result forString:[msgColoums objectAtIndex:4] range:&range error:&error];
NSLog(@"Error in Parsing = %@", error);
INLog(@"Date From DF = %@", [df dateFromString:@"2011-12-14T16:31:26.0000000"]);
该代码为 dateFromString
消息返回 null
。
错误为 NSInvalidValue=2011-12-14T16:31:26.0000000
。
如果我将格式字符串更改为
[df setDateFormat:@"yyyy-MM-dd"];
那么它就会起作用,所以问题出在时间部分。
有人可以解释一下吗?
I have this Following date Formatter code
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-ddThh:mm:ss"];
NSDate *result = nil;
NSRange range = NSMakeRange(0, 10);
NSError *error = nil;
[df getObjectValue:&result forString:[msgColoums objectAtIndex:4] range:&range error:&error];
NSLog(@"Error in Parsing = %@", error);
INLog(@"Date From DF = %@", [df dateFromString:@"2011-12-14T16:31:26.0000000"]);
The code returns null
for the dateFromString
message.
The Error is NSInvalidValue=2011-12-14T16:31:26.0000000
.
If I change the formatting string to
[df setDateFormat:@"yyyy-MM-dd"];
then it will work, so the problem is in the time part.
Will someone please shed some light on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
引用文字
T
Try:
to quote the literal
T