Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone display date using a user locale but in other language

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

like image 656
CristiC Avatar asked Nov 18 '10 16:11

CristiC


1 Answers

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]];
like image 117
Ole Begemann Avatar answered Sep 22 '22 15:09

Ole Begemann