开发者

NSArray with days of the week and months of the year

开发者 https://www.devze.com 2023-03-10 05:26 出处:网络
Is there a way I can get an array of (string of days of the week) so: monday, tuesday, wednesday.... and also for months?

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消