Don't like ads? PRO users don't see any ads ;-)

Set preferred user language as NSDateFormatter locale

By: feb on Jul 16th, 2012  |  syntax: Objective C  |  size: 0.27 KB  |  hits: 47  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  2.  
  3. NSString *preferredLanguage = [[NSLocale preferredLanguages] objectAtIndex:0];
  4. NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:preferredLanguage] autorelease];
  5.  
  6. [dateFormatter setLocale:locale];