Skip navigation.
 
mlRe: Short Date Format for NSCalendarDate in bound NSTableColumn
FROM : Jonathan Fewtrell
DATE : Sat Apr 16 19:59:33 2005

On 16 Apr 2005, at 17:17, glenn andreas wrote:

> you could write your own NSDateFormatter subclass instead (and then
> use that).  Something roughly like:
>
> @interface ShortDateFormatter: NSDateFormatter
> @end
>
> @implementation ShortDateFormatter
> - (NSString *) dateFormat
> {
>     return [[NSUserDefaults standardUserDefaults] stringForKey:
> NSShortDateFormatString];
> }
> @end


As a follow-up to this, I found that overriding -dateFormat doesn't
work. It still picks up the format from the tokens in IB. I found I
needed to override -initWithDateFormat instead:

- (id)initWithDateFormat:(NSString *)format
allowNaturalLanguage:(BOOL)flag
{
   NSString *formatJF;
   
   formatJF = [[NSUserDefaults standardUserDefaults] stringForKey:
NSShortDateFormatString];
   self = [super initWithDateFormat:formatJF allowNaturalLanguage:flag];
   return self;
}

Not really sure why this should be, but the docs do actually say "You
must specify a format string whenever you create a date formatter".

Related mailsAuthorDate
mlShort Date Format for NSCalendarDate in bound NSTableColumn Jonathan Fewtrell Apr 16, 18:06
mlRe: Short Date Format for NSCalendarDate in bound NSTableColumn glenn andreas Apr 16, 18:17
mlRe: Short Date Format for NSCalendarDate in bound NSTableColumn Jonathan Fewtrell Apr 16, 18:44
mlRe: Short Date Format for NSCalendarDate in bound NSTableColumn glenn andreas Apr 16, 18:49
mlRe: Short Date Format for NSCalendarDate in bound NSTableColumn Jonathan Fewtrell Apr 16, 18:55
mlRe: Short Date Format for NSCalendarDate in bound NSTableColumn Jonathan Fewtrell Apr 16, 19:59