• 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
Re: NSDateFormatter formats from NSLocale
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDateFormatter formats from NSLocale


  • Subject: Re: NSDateFormatter formats from NSLocale
  • From: "Sean McBride" <email@hidden>
  • Date: Tue, 11 Aug 2009 12:48:57 -0400
  • Organization: Rogue Research Inc.

On 8/11/09 6:39 PM, Houdah - ML Pierre Bernard said:

>I am trying to format dates for display. So far I have been using this
>formatter:
>
>	NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init]
>autorelease];
>
>	[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
>	[dateFormatter setDateStyle:NSDateFormatterShortStyle];
>	[dateFormatter setTimeStyle:kCFDateFormatterMediumStyle];
>
>
>Now, I want to add leading zeros to days and month values. It seems
>there is no way of teaching the above formatter to do so. It goes with
>whatever format the user has set in System Preferences.
>
>Thus I am trying the below formatter:
>
>	NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init]
>autorelease];
>
>	[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
>	[dateFormatter setDateFormat:@"dd/mm/yy hh:MM:ss a"];
>
>This works fine, except for the fact that I have now hardcoded the
>fact that I display day/month/year rather than month/day/year.
>
>It would seem that NSLocale should know about the user's preferences.
>Yet I can find no way to query it for date format.

So you want to use the user's preference and yet you don't.  The choice
of leading zeros or no is part of the user's choice.  But if you must,
you could get the user's format string and carefully alter it to add
leading zeros.

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSDateFormatter formats from NSLocale
      • From: Alex Kac <email@hidden>
    • Re: NSDateFormatter formats from NSLocale
      • From: Houdah - ML Pierre Bernard <email@hidden>
References: 
 >NSDateFormatter formats from NSLocale (From: Houdah - ML Pierre Bernard <email@hidden>)

  • Prev by Date: Re: NSUserDefault and Negative numerical arguments (Was: Posting mouse clicks with multiple displays)
  • Next by Date: Re: NSDateFormatter formats from NSLocale
  • Previous by thread: NSDateFormatter formats from NSLocale
  • Next by thread: Re: NSDateFormatter formats from NSLocale
  • Index(es):
    • Date
    • Thread