views:

40

answers:

1

I'm extracting strings from a text that represent dates. They look like this:

Monday August 16, 2010 05:28 AM EST

I'm trying to parse them with a NSDateFormatter. I've set its format to:

[dateFormatter setDateFormat:@"EEEE MMMM d, YYYY h:mm a z"];

However, this doesn't work. For the example I gave above, if I convert the string to a date and then that date to a string, the date formatter returns this:

Monday December 28, 2009 5:28 AM EST

What am I doing wrong?

EDIT: It seems to work when using the format [dateFormatter setDateFormat:@"EEEE MMMM d, y h:mm a z"];. Strange...

A: 

Will,

NSDateFormatter uses the Unicode standard for formatting dates. As you've found, "y" works, but "YYYY" doesn't. If you see the spec (referenced several layers deep in the Apple documentation, so not easy to find) you'll see that "Y" has this note: "Year (of "Week of Year"), used in ISO year-week calendar. May differ from calendar year."

Here is the link to the specification.

I know you've fixed it yourself, but this may help explain why "Y" didn't work for you.

Tim Kemp