2

I want to display a date like this : weekday 7 month. I did this and I have the correct syntax.

NSDateFormatter* df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"EEEE dd MMMM"];
[df setTimeZone:[NSTimeZone localTimeZone]];

The result logged is : Saturday 16 March. I just want to have the french date, not the english one. I try to set the local time zone but it changes nothing. Do you have an idea of how to do this ?

Seb
  • 545
  • 9
  • 29

2 Answers2

7

initialize a locale using an identifer. you can get all available identifiers from

[NSLocale availableLocaleIdentifiers];

i believe @"fr_BI" is one of the french identifiers

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"fr_BI"];
[dateFormatter setLocale:locale];
tzl
  • 1,540
  • 2
  • 20
  • 31
  • To choose the appropriate french identifier, use the code below : NSArray * bb = [NSLocale availableLocaleIdentifiers]; NSPredicate * bPredicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] 'fr'"]; NSArray * beginWithFr = [bb filteredArrayUsingPredicate:bPredicate]; for (NSString * elt in beginWithFr) { NSLog(@"%@ : %@",elt, [[[NSLocale alloc] initWithLocaleIdentifier:elt] localizedStringForLocaleIdentifier:elt]); } – XLE_22 Mar 13 '18 at 09:29
2

You set the locale of the date formatter using the appropriate NSLocale object.

Also, be wary of hard-coded date formats like that. Your users may not like seeing dates in that format, so you should run the format string through +[NSDateFormatter dateFormatFromTemplate:options:locale:] first. The WWDC 2012 session "Internationalization Tips & Tricks" had a bunch of useful information about this.

Dave DeLong
  • 242,470
  • 58
  • 448
  • 498