• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
User Date Formatter (was Re: table column with <date value> null placeholder)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

User Date Formatter (was Re: table column with <date value> null placeholder)


  • Subject: User Date Formatter (was Re: table column with <date value> null placeholder)
  • From: glenn andreas <email@hidden>
  • Date: Mon, 9 May 2005 15:08:01 -0500


On May 9, 2005, at 2:42 PM, Sean McBride wrote:

On 2005-05-06 17:06, Eric Friedman said:

Sean, I'm interested in your comment about date format as a user
preference.  Of course Interface Builder's formatter wants me to
choose exactly one format string.

Yes, quite annoying.

I suppose what you say could be
done through user preferences, but I'm curious -- do a lot of folks go
to this trouble?

Lots do, lots don't; but you should. ;)

This snippit will get you started:

NSString* sdf = [[NSUserDefaults standardUserDefaults] stringForKey:
NSDateFormatString];
NSDictionary*	locale = [[NSUserDefaults standardUserDefaults]
dictionaryRepresentation];
[aDate descriptionWithCalendarFormat:sdf locale:locale];

Sadly, passing nil's to descriptionWithCalendarFormat does not get you
localised date strings.

I would LOVE for someone to point out an easier way to get a localised,
in-the-user's-format string from an NSDate.


Make a custom subclass of NSFormatter:

@interface UserDateFormatter: NSDateFormatter
@end

Drag that header file to IB so this class is available in your NIB.

@implementation UserDateFormatter
- (id) init
{
self = [super init];
if (self) {
[self setFormatString: [[NSUserDefaults standardUserDefaults] stringForKey: NSDateFormatString]];
}
return self;
}
@end


Attach the standard date formatter. Switch to outline view and tunnel down through your UI until you find that date formatter (it will show up there as a selectable item). Switch to custom class in the inspector, and select your UserDateFormatter class.

Repeat for as many places you want to use the user date. You might want to make another version that does the user short date format.

Done.

Glenn Andreas                      email@hidden 
 <http://www.gandreas.com/> oh my!
quadrium | build, mutate, evolve | images, textures, backgrounds, art

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: User Date Formatter (was Re: table column with <date value> null placeholder)
      • From: "Sean McBride" <email@hidden>
References: 
 >table column with <date value> null placeholder (From: Eric Friedman <email@hidden>)
 >Re: table column with <date value> null placeholder (From: "Sean McBride" <email@hidden>)
 >Re: table column with <date value> null placeholder (From: Eric Friedman <email@hidden>)
 >Re: table column with <date value> null placeholder (From: "Sean McBride" <email@hidden>)

  • Prev by Date: Re: multiple inheritance equivalent in Core Data?
  • Next by Date: Re: multiple mdimporters not managed by Spotlight ??? critical bug IMO
  • Previous by thread: Re: table column with <date value> null placeholder
  • Next by thread: Re: User Date Formatter (was Re: table column with <date value> null placeholder)
  • Index(es):
    • Date
    • Thread