views:

41

answers:

1

I have a table view that displays dates using a NSDateFormatter to format them using the Full date style (today would be formatted as "Friday, September 24, 2010" or in German "Freitag, 24. September 2010"). But when editing the date the formatter forces the user to type the date in the same format. How can I make the formatter accept dates in different formats on input? Ideally the formatter should use some heuristic to automatically detect the entered format.

I tried setting the lenient property in code, but this doesn’t change the observed behavior at all.

Lots of programs automatically detect the inputted date format, so this has to be possible. Or are they all using their own implementation?

A: 

Maybe this section of the Data Formatting Guide can help:

The v10.4 behavior mode allows more configurability and better localization; you should use it for any new projects, and ideally upgrade any existing code that uses v10.0 behavior to use v10.4 behavior.

For backwards binary compatibility, the default behavior for NSDateFormatter on Mac OS X version 10.4 is the v10.0 behavior. On Mac OS X version 10.5 and later, however, the default is the v10.4 behavior. You can set the default behavior of all instances of NSDateFormatter to the v10.4 behavior by invoking the class method, setDefaultFormatterBehavior: with the argument NSDateFormatterBehavior10_4. You can also set the behavior for any instance individually by invoking setFormatterBehavior:.

Joshua Nozzi
This doesn’t really help. When switching to the v10.0 behavior it accepts dates in different formats, but it ignores the locale and insists on the *month.day.year* format which is wrong for Germany where we use the *day.month.year* form.
Sven