• 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: Houdah - ML Pierre Bernard <email@hidden>
  • Date: Tue, 11 Aug 2009 23:01:12 +0200

Figured out one way to get the desired result. But really don't like it. I'd much rather have NSLocal tell me if day or months value should go first.

Anyway, here it goes:

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];

[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];


NSMutableString *dateFormat = [NSMutableString stringWithString: [dateFormatter dateFormat]];

[dateFormat replaceOccurrencesOfString:@"d" withString:@"dd" options: 0 range:NSMakeRange(0, [dateFormat length])];
[dateFormat replaceOccurrencesOfString:@"ddd" withString:@"dd" options:0 range:NSMakeRange(0, [dateFormat length])];
[dateFormat replaceOccurrencesOfString:@"ddd" withString:@"dd" options:0 range:NSMakeRange(0, [dateFormat length])];
[dateFormat replaceOccurrencesOfString:@"M" withString:@"MM" options: 0 range:NSMakeRange(0, [dateFormat length])];
[dateFormat replaceOccurrencesOfString:@"MMM" withString:@"MM" options:0 range:NSMakeRange(0, [dateFormat length])];
[dateFormat replaceOccurrencesOfString:@"MMM" withString:@"MM" options:0 range:NSMakeRange(0, [dateFormat length])];
[dateFormat replaceOccurrencesOfString:@"h" withString:@"hh" options: 0 range:NSMakeRange(0, [dateFormat length])];
[dateFormat replaceOccurrencesOfString:@"hhh" withString:@"hh" options:0 range:NSMakeRange(0, [dateFormat length])];
[dateFormat replaceOccurrencesOfString:@"hhh" withString:@"hh" options:0 range:NSMakeRange(0, [dateFormat length])];
[dateFormat replaceOccurrencesOfString:@"m" withString:@"mm" options: 0 range:NSMakeRange(0, [dateFormat length])];
[dateFormat replaceOccurrencesOfString:@"mmm" withString:@"mm" options:0 range:NSMakeRange(0, [dateFormat length])];
[dateFormat replaceOccurrencesOfString:@"mmm" withString:@"mm" options:0 range:NSMakeRange(0, [dateFormat length])];
[dateFormat replaceOccurrencesOfString:@"s" withString:@"ss" options: 0 range:NSMakeRange(0, [dateFormat length])];
[dateFormat replaceOccurrencesOfString:@"sss" withString:@"ss" options:0 range:NSMakeRange(0, [dateFormat length])];
[dateFormat replaceOccurrencesOfString:@"sss" withString:@"ss" options:0 range:NSMakeRange(0, [dateFormat length])];


	[dateFormatter setDateFormat:dateFormat];
	[dateFormatter setLenient:YES];

Pierre


On Aug 11, 2009, at 6:51 PM, Houdah - ML Pierre Bernard wrote:

Hi Sean,

I want to respect the user's locale, yet ignore his/her preferences as to formatting.

I thought about modifying the format I get from the standard styles. I would however expect NSLocale to know the correct order of elements in the date format.

Pierre

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

_______________________________________________

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


References: 
 >NSDateFormatter formats from NSLocale (From: Houdah - ML Pierre Bernard <email@hidden>)
 >Re: NSDateFormatter formats from NSLocale (From: "Sean McBride" <email@hidden>)
 >Re: NSDateFormatter formats from NSLocale (From: Houdah - ML Pierre Bernard <email@hidden>)

  • Prev by Date: Forcing a cell's field editor to send control:textShouldEndEditing: when leaving a cell
  • Next by Date: Re: Forcing a cell's field editor to send control:textShouldEndEditing: when leaving a cell
  • Previous by thread: Re: NSDateFormatter formats from NSLocale
  • Next by thread: Re: NSDateFormatter formats from NSLocale
  • Index(es):
    • Date
    • Thread