Search code examples
iosobjective-cnsdatensdateformatternstimezone

Change language for NSDate weekday and month


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 ?


Solution

  • 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.