Internationalized Dates

  • Hi,

    I'm trying to have a date drawn in a format to fit the width of a
    column in a table view. Drawing and determining which to use is
    obviously easy, the question is, where the heck do you get the
    formats from?

    This works wonderfully for us American folk:

    @"%A, %B %e, %Y, %I:%S %p";
    @"%B %e, %Y, %I:%S %p";
    @"%b %e, %Y, %I:%S %p";
    @"%m/%d/%y, %I:%S %p";
    @"%m/%d/%y";

    But it sucks for internationals, obviously.

    This I thought might be a decent approach:

    [standardUserDefaults objectForKey:NSTimeDateFormatString];
    [standardUserDefaults objectForKey:NSDateFormatString];
    [standardUserDefaults objectForKey:NSShortTimeDateFormatString]
    [standardUserDefaults objectForKey:NSShortDateFormatString];

    But it's not much better. Who needs the time zone for something they
    modified (NSTimeDateFormatString)? And there's no intermediary
    between NSDateFormatString and NSShortXXXFormatString (iow, with
    abbreviated months or days of the week etc).

    So I'd much prefer to use the literals, but how would I handle
    internationalizing them? I would localize the constant, but there are
    no other localizations at the moment. I suppose I could just check
    the locale and switch between the literals and the format from user
    defaults.

    What do you guys do?

    --
    Seth Willits
  • On Oct 31, 2006, at 8:55 PM, Seth Willits wrote:

    > I'm trying to have a date drawn in a format to fit the width of a
    > column in a table view. Drawing and determining which to use is
    > obviously easy, the question is, where the heck do you get the
    > formats from?

    Unless you must target Panther or earlier, the best thing to do is to
    use the new-style NSDateFormatters and then just use -setDateStyle:
    and -setTimeStyle: to build the proper formatter. Doing this gives
    you a lot more control over formatting than using the NSUserDefaults
    constants. If you must target Panther or earlier, then you must use
    the NSUserDefaults constants.

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • On Oct 31, 2006, at 8:12 PM, Nick Zitzmann wrote:

    >> I'm trying to have a date drawn in a format to fit the width of a
    >> column in a table view. Drawing and determining which to use is
    >> obviously easy, the question is, where the heck do you get the
    >> formats from?
    >
    > Unless you must target Panther or earlier, the best thing to do is
    > to use the new-style NSDateFormatters and then just use -
    > setDateStyle: and -setTimeStyle: to build the proper formatter.
    > Doing this gives you a lot more control over formatting than using
    > the NSUserDefaults constants. If you must target Panther or
    > earlier, then you must use the NSUserDefaults constants.

    I forgot about that. I was originally targeting Panther but have been
    Tiger-only for... sheesh... a year? Any way, I now have a good
    solution (to me).

    --
    Seth Willits
previous month november 2006 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      
Go to today