Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSArray with days of the week and months of the year

Is there a way I can get an array of (string of days of the week) so: monday, tuesday, wednesday.... and also for months?

I can manually create that array, but I was wondering if there a more eloquent way of doing this... Thanks.

like image 396
sumderungHAY Avatar asked Jan 20 '23 14:01

sumderungHAY


1 Answers

This code;

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSArray *weekdays = [dateFormatter weekdaySymbols];

will give you the the weekdays in the users current locale.

If you want a particular locale set the desired locale on the dateFormatter.

Creating an NSDateFormatter is expensive so create one and reuse it.

like image 130
Bill Dudney Avatar answered Jan 27 '23 21:01

Bill Dudney