runmad
runmad

Reputation: 14886

NSDate format correct on Simulator, incorrect on device

I'm using NSDateFormatter to format dates to relative dates. In Simulator, the dates appear correctly as "November 12, 2012", however on my device the same date appears as "2012-11-12". I'm running the same OS version both.

Here's the code I am using:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setDoesRelativeDateFormatting:YES];
NSString *dateString = [dateFormatter stringFromDate:dateToDisplay];

Thanks!

Upvotes: 1

Views: 844

Answers (1)

jimpic
jimpic

Reputation: 5520

Probably different localization. Check Settings --> General --> International on both your device and simulator. You can set the locale of your dateFormatter like

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en/US"];
[dateFormatter setLocale:locale];

Upvotes: 6

Related Questions