1

我在解析日期字符串时遇到了一个奇怪的问题。我有一个日期格式化程序,格式为:

yyyy-MM-dd HH:mm:ss.SSSSSSZZ

和日期字符串:

2012-11-09 10:47:01.999804+01

dateFromString 方法返回 nil,但是当我将日期字符串更改为 ie 时:

2012-11-09 10:47:01.989804+01

它有效......有谁知道为什么微秒值有这样的限制,我怎样才能正确解析上面的日期?

我可以用正则表达式解析它并剪切整个 SSSSSS 部分,但通常有时我需要比较日期,这样它们就不会匹配,这会导致更多问题。

4

2 回答 2

0

I had no end of niggly issues doing this, finally got it to work but stripped the point seconds off and used the format as follows

#define DATEFORMATSTRINGTIMEZONE @"yyyy-MM-dd HH:mm ZZZ"

a bit like you say. I have to admit a bit more into the project I realized this was a very difficult method of sharing dates and instead adopted epoch time which has saved all headaches I was having regarding timezones... I'd highly recommend it if you have the luxury of changing the incoming data format.

Whilst I'm not sure why yours doesn't parse, I would question the ZZ instead of the ZZZ at the end given you have +01 not +1?

于 2013-01-03T15:04:09.850 回答
0

我终于解决了这个问题。

我正在修改日期格式和日期字符串以删除微秒,以便我可以正确解析日期。然后我只添加从原始日期字符串解析的微秒。

于 2013-01-26T18:38:35.690 回答