日期格式给出 null
我有字符串“24 Jan 2012 09:21:21 +0000”,我想将其设为 NSDate 对象,因为它
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterFullStyle];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"];
NSDate* date = [dateFormatter dateFromString:dateStr];
NSLog(@"%@",date);
给了我 (null)
我应该做什么才能以我想要的格式获取日期。
I have string "24 Jan 2012 09:21:21 +0000" and I want to make it a NSDate object as
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterFullStyle];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"];
NSDate* date = [dateFormatter dateFromString:dateStr];
NSLog(@"%@",date);
gives me (null)
What i should do to get date in the format I want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于您有特定的日期格式,因此您可以设置格式化程序以匹配它。
您可以在此处查看日期说明符列表。
Since you have a specific date format, you can set your formatter up to match it.
You can see the list of date specifiers here.
2012 年 1 月 24 日 09:21:21 +0000
24 Jan 2012 09:21:21 +0000
我没有要验证的 obj C 环境,但您的日期字符串是“年月日”,您要处理的输入是“日(短)月年”
I don't have an obj C environment to verify, but your date string is "year month day" and the input you want to handle is "day (short)month year"