John Lane
John Lane

Reputation: 1132

NSDateFormatter date format string

I have an odd issue with an NSDateFormatter, I am passing the following string as a date format "dd/MM/yy"

If I enter 50 for the year I get a conversion to 1950 however anything below that for instance 49 results in 2049. Any ideas how I can remedy this?

Many thanks.

Upvotes: 1

Views: 567

Answers (1)

Michael Dautermann
Michael Dautermann

Reputation: 89509

It sounds like you'll need to force a four digit response (or programmatically prepend two digits of "19") to wherever you're drawing your string from. Lots of people are using dates in the near to mid-term future like "12/21/12" (end of the Mayan Calendar era) so it's natural that a 2 digit year assumes 2000+ for digits 1-50 and 1999- for digits (50-99).

I'm also seeing a number of Google hits on the keyword terms "NSDateFormatter" & "century", b.t.w.

Upvotes: 2

Related Questions