سؤال

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 ?

هل كانت مفيدة؟

المحلول 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.

نصائح أخرى

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];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top