将 NSString 转换为 NSDate,字符串格式为“Sun, 08 Jan 2012 13:57:38 +0000”
我实际上检索格式为“Sun, 08 Jan 2012 13:57:38 +0000”的字符串日期 为此,我使用日期格式“EEE,dd MMM yyyy HH:mm:ss ZZZ” 但它不起作用......
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZZ"];
NSLog(@"%@",[dict objectForKey:@"created_at"]);
NSDate *dateFromString = [dateFormatter dateFromString:[dict objectForKey:@"created_at"]];
NSLog(@"%@",dateFromString);
对于第一个 NSLog,它显示我“Sun, 08 Jan 2012 13:57:38 +0000” 但第二个是(空)
我不明白我错在哪里。 如果您发现有问题,请告诉我。
谢谢
I actually retrieve string date with the format "Sun, 08 Jan 2012 13:57:38 +0000"
For that I use the dateFormat "EEE, dd MMM yyyy HH:mm:ss ZZZ"
But it doesn't work...
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZZ"];
NSLog(@"%@",[dict objectForKey:@"created_at"]);
NSDate *dateFromString = [dateFormatter dateFromString:[dict objectForKey:@"created_at"]];
NSLog(@"%@",dateFromString);
For the first NSLog it displays me "Sun, 08 Jan 2012 13:57:38 +0000"
But the second is (null)
I don't understand where I am wrong.
Please tell me if you see something wrong.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的日期字符串是英文的。如果您的设备或模拟器区域设置设置为另一种语言,则可能是问题所在。如果是这样,您需要将 NSDateFormatter 的区域设置设置为英语。
像这样:
Your date string is in English. If your device or simulator locale is set to another language, that could be the problem. If so, you need to set the locale for the NSDateFormatter to English.
Like this: