Cocoa - Localized string from NSDate, NSCalendarDate

I am using NSDate to get a string like "June 18th 09", with the code:

NSDate *theDate = [NSDate date]; NSString *dateString = [theDate descriptionWithCalendarFormat:@"%d %b %y" timeZone:nil locale: nil]; 

It works, but only leads to English. I need the result to be localized in the user's default language.

Is Cocoa (Mac OS X 10.4, 10.5 in this case) a tool for this localization, or do I need to manually localize my own for each case of the day and month?

(I provided a locale, but although this provides a language-specific binding based on the language, it does not seem to do any localization of daytime month names.)

+3
source share
2 answers

Here is an excerpt from Apple :

 NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:118800]; NSString *formattedDateString = [dateFormatter stringFromDate:date]; NSLog(@"formattedDateString for locale %@: %@", [[dateFormatter locale] localeIdentifier], formattedDateString); 
+22
source

One line of code appears:

 [dateFormatter setLocale:usLocale]; 
+3
source

Source: https://habr.com/ru/post/971898/


All Articles