MagicalRecord日期解析 [英] MagicalRecord date parsing

查看:118
本文介绍了MagicalRecord日期解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的日期格式如下:

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

这是:


  1. 四位数年

  2. 连字符

  3. 零填充月份

  4. 连字符

  5. 每月零填充

  6. 'T'字符

  7. 零填充小时

  8. ':'character

  9. 零填充分钟

  10. ':'character

  11. 零填充第二

  12. 时区(来自GMT和分隔冒号的方向)

  1. four digit year
  2. hyphen
  3. zero-padded month
  4. hyphen
  5. zero-padded day of month
  6. 'T' character
  7. zero-padded hour
  8. ':' character
  9. zero-padded minute
  10. ':' character
  11. zero-padded second
  12. 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屋!

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