Date formatters

I ran into the new mode of operation for NSDateFormatter for the first time tonight and I’m really happy about the changes.  Formatting a date using the format the user configured in the International preferences panel in System Preferences is now 2 lines of code.  You don’t have to look up the format strings in user defaults anymore.  Just call setDateStyle: to set the date format and setTimeStyle: to set the time format.  Valid styles are: NSDateFormatterNoStyle, NSDateFormatterShortStyle, NSDateFormatterMediumStyle, NSDateFormatterLongStyle, and NSDateFormatterFullStyle.  They also added a couple new convenience methods and allowed for a bit more configurability, but the date styles should generally be used so that the user’s settings are respected. 

The only bad part about the new mode is that for the time being Interface Builder only uses the old v10.0 behavior and not the new v10.4 mode.  A formatter for a table column or other UI element has to be manually added in code.  Hopefully the new mode gets added to IB soon.

Leave a Reply