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

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

问题描述

我使用的NSDateFormatter在模拟器中工作正常,但是当我在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 :(特定GMT时区名称)

  • Z:+0000(RFC 822 Timezone

感谢您的帮助!

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

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