FROM : Nick Zitzmann
DATE : Mon Apr 14 19:09:44 2008
On Apr 13, 2008, at 11:21 PM, Derrick Bass wrote:
> In one program that links to this framework, the date is getting
> parsed correctly. But in another, the very same string is coming
> back as "1969-12-31 16:00:00 -0800"! Using -
> [getObjectValue:forString:range:error:] gives the same results....
> no error.
>
> What could be causing the different behaviors and how do I get the
> string to parse no matter what?
There are two styles of NSDateFormatter: The pre-Tiger style (10.0)
and the Tiger & later style (10.4). The latter supports non-Gregorian
calendars and automatically fetching properly localized date
formatters, but when parsing strings into dates, they require the
format to be extremely strict or they don't work. The former only
supports the Gregorian calendar, and the methods of getting properly
localized date formats have been deprecated, but they are much more
flexible in the kind of input they take.
So make sure both formatters are of the 10.0 style.
Nick Zitzmann
<http://www.chronosnet.com/>
DATE : Mon Apr 14 19:09:44 2008
On Apr 13, 2008, at 11:21 PM, Derrick Bass wrote:
> In one program that links to this framework, the date is getting
> parsed correctly. But in another, the very same string is coming
> back as "1969-12-31 16:00:00 -0800"! Using -
> [getObjectValue:forString:range:error:] gives the same results....
> no error.
>
> What could be causing the different behaviors and how do I get the
> string to parse no matter what?
There are two styles of NSDateFormatter: The pre-Tiger style (10.0)
and the Tiger & later style (10.4). The latter supports non-Gregorian
calendars and automatically fetching properly localized date
formatters, but when parsing strings into dates, they require the
format to be extremely strict or they don't work. The former only
supports the Gregorian calendar, and the methods of getting properly
localized date formats have been deprecated, but they are much more
flexible in the kind of input they take.
So make sure both formatters are of the 10.0 style.
Nick Zitzmann
<http://www.chronosnet.com/>
| Related mails | Author | Date |
|---|---|---|
| Derrick Bass | Apr 14, 07:21 | |
| Nick Zitzmann | Apr 14, 19:09 | |
| Derrick Bass | Apr 15, 08:04 |






Cocoa mail archive

