n179911
n179911

Reputation: 20301

iOS Set Date format based on user locale

I am trying to set the date format based on user locale:

So I followed the answer for this question:

Specifically, I did:

NSDate* now = [NSDate date];
NSDateFormatter* df = [[NSDateFormatter alloc] init];
[df setDateStyle:NSDateFormatterMediumStyle];
NSString* myString = [df stringFromDate:now];

My question is: when I set the locale to Italy, the date shows as "24/nov/2014". Why is the month shown as "nov" instead of "11"?

Upvotes: 0

Views: 581

Answers (1)

David Rönnqvist
David Rönnqvist

Reputation: 56625

According to the documentation, the "Medium" style (that you are specifying) for English is shown as "Nov 23, 1937" so it shouldn't be very surprising that it was shown as "nov" instead of "11" in Italian.

NSDateFormatterMediumStyle
Specifies a medium style, typically with abbreviated text, such as “Nov 23, 1937”"

It looks like maybe you are looking for the "Short" style. Note that some countries present are shown as day, month, year while others prefer year, month, day or even month, day, year1 (as seen below):

NSDateFormatterShortStyle
Specifies a short style, typically numeric only, such as “11/23/37”

Upvotes: 2

Related Questions