MagicalRecord日期解析 [英] MagicalRecord date parsing
问题描述
我的日期格式如下:
2013-05-04T05:07:09 + 00:00
我正在使用MagicalRecord自动映射NSDate。据我所知,上述日期格式应符合MagicalRecord的默认日期格式: yyyy-MM-dd'T'HH:mm:ss'Z'
。
I'm using MagicalRecord to map the NSDate automatically. As far as I can see the above date format should comply with MagicalRecord's default date format: yyyy-MM-dd'T'HH:mm:ss'Z'
.
我尝试在属性的用户信息中使用自定义 dateFormat
条目(参见这篇文章):
I have tried with a custom dateFormat
entry in the attribute's user info (see this article):
yyyy-MM-ddTHH:mm:ss + Z
, yyyy-MM-dd T HH:mm:ss Z
, yyyy-MM-dd'T'HH:mm:ss'+'Z
但没有一个工作,以使其正确解析日期,无论设置自定义 dateFormat
或使用MagicalRecord,它总是返回 nil
默认格式。
but none of them work in order to have it parse the date properly and it always returns nil
regardless of setting a custom dateFormat
or using MagicalRecord's default format.
推荐答案
让我们来看看你的字符串:
Let's look at your string:
2013-05-04T05:07:09+00:00
这是:
- 四位数年
- 连字符
- 零填充月份
- 连字符
- 每月零填充
- 'T'字符
- 零填充小时
- ':'character
- 零填充分钟
- ':'character
- 零填充第二
- 时区(来自GMT和分隔冒号的方向)
- four digit year
- hyphen
- zero-padded month
- hyphen
- zero-padded day of month
- 'T' character
- zero-padded hour
- ':' character
- zero-padded minute
- ':' character
- zero-padded second
- timezone (with direction from GMT and a separating colon)
因此,根据日期格式说明符文档,你想要的模式是:
Thus, according to the date format specifiers documentation, the pattern you'd want is:
yyyy-MM-dd'T'HH:mm:ssZZZZZ
另外,请务必使用 en_US_POSIX
区域设置 NSDateFormatter
。
Also, be sure to use the en_US_POSIX
locale with the NSDateFormatter
.
这篇关于MagicalRecord日期解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!