开发者

Is the starting day of the week stored in NSLocale somewhere?

开发者 https://www.devze.com 2023-03-09 20:23 出处:网络
I live in the Netherlands. We Dutch people like to see Monday as the start of the week. I know that people in the US like to consider Sunday as the start of the week. Silly Americans ;)

I live in the Netherlands. We Dutch people like to see Monday as the start of the week. I know that people in the US like to consider Sunday as the start of the week. Silly Americans ;)

If I want to present a week view to my g开发者_JAVA技巧lobal users, can I get the preferred starting day of the week from NSLocale, or is a settings panel the only way to go?

Cheers, EP.


Use the following code:

NSCalendar *calendar = [[NSLocale currentLocale] objectForKey:NSLocaleCalendar];
NSUInteger firstDay = [calendar firstWeekday];

You may also check this relevant question.


The accepted answer is actually incorrect. Here's the correct code:

NSCalendar *calendar = [[NSLocale currentLocale] objectForKey:NSLocaleCalendar];
self.weekStartsOnDay = [calendar firstWeekday];

The issue is that the object referenced by NSLocaleCalendar is actually a calendar.

0

精彩评论

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