我的NSDateFormatter只在iPhone模拟器工作 [英] my NSDateFormatter works only in the iPhone simulator

查看:128
本文介绍了我的NSDateFormatter只在iPhone模拟器工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用NSDateFormatter在模拟器中工作正常,但我得到一个nil当我在iPhone中运行它。我硬编码日期以确保格式,但它仍然失败。

I use a NSDateFormatter which works fine in the simulator, but I get a nil when I run it in the iPhone. I hardcoded the date to be sure of the format, but it fails anyway.

NSString *strPubDate = @"Fri, 8 May 2009 08:08:35 GMT";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss Z"];

NSDate *myDate = [dateFormatter dateFromString:strPubDate];

我试过在iPhone上使用不同的区域设置,语言等。

I tried with different region settings, languages etc. on the iPhone. Any idea what is going wrong?

推荐答案

此代码似乎在GMT标签上正常工作。

This code seems to work correctly against the "GMT" tag.

NSString *strPubDate = @"Fri, 8 May 2009 08:08:35 GMT";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss zzzz"];
NSDate *myDate = [dateFormatter dateFromString:strPubDate];

RFC822日期和时间规范使用几个区域标签,我发现正确的符号来解析GMT标签格式化iPhone的字符串NSDateFormatter

RFC822 Date and Time specs use a few "zone" tags and I found the correct symbol to parse the "GMT" tag Format String for the iPhone NSDateFormatter


  • z〜zzz :(特定GMT时区缩写)

  • zzzz:
  • Z:+0000(RFC 822时区

感谢您的帮助!

这篇关于我的NSDateFormatter只在iPhone模拟器工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆