Question

Is there any solution to display to the user a date using his locale settings but the words to be in a different language?

What I want is to display to a user that has set up en_US a date in german language (month names, weekdays for example).

Was it helpful?

Solution

Good question. It is possible if you first create an NSDateFormatter with the user's locale (default), set its style, then store the current date format. After that, set the locale to the language you want to display and reset the date format:

NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
[df setDateStyle:NSDateFormatterFullStyle];
NSString *usersDateFormat = [df dateFormat];
[df setLocale:[[[NSLocale alloc] initWithLocaleIdentifier(@"de_DE")] autorelease]];
[df setDateFormat:usersDateFormat];
NSString *dateString = [df stringFromDate:[NSDate date]];

OTHER TIPS

The iOS Class Reference for NSDateFormatter has sample code for this:

http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html

It is in the Overview section.

Basically, you manually set the locale, and the formatter formats the given date with that locale.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top