cspam
cspam

Reputation: 2941

iOS - setting NSDate for localization using shorthand for the day

So i would like to set the date into a label with the following format

Mon, Nov 17, 2014. Tue,... Wed... (depending on which day)

Now I can get this from the following setDateFormat:

[dateFormatter setDateFormat:@"EEE, MMM d, yyyy"];

When i change settings however(lets say Denmark), I obviously still get Mon, Nov 17, 2014.

I havent found a date style that is going to give me what i need here. Is the best solution to get the day of the week and then add that shorthand to the beginning of the NSDateFormatterMediumStyle for the normal Month, day, year or am I missing something in the docs that would give me what i want here?

Upvotes: 0

Views: 59

Answers (1)

rmaddy
rmaddy

Reputation: 318814

You can achieve the desired results by doing the following:

dateFormatter = [[NSDateFormatter alloc] init];
NSString *format = [NSDateFormatter dateFormatFromTemplate:@"EEE, MMM d, yyyy" options:0 locale:[NSLocale currentLocale]];
[dateFormatter setDateFormat:format];

format will be adjusted to best suit the current locale.

Upvotes: 1

Related Questions