5

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 global 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.

epologee
  • 11,229
  • 11
  • 68
  • 104

2 Answers2

7

Use the following code:

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

You may also check this relevant question.

Community
  • 1
  • 1
Anton
  • 2,342
  • 15
  • 17
  • Actually the link you provided before your edit was exactly what I was looking for, even though I said 'day' when I meant 'date'. Care to put that in there as well? Thanks! – epologee May 30 '11 at 22:10
  • @epologee Sorry, but what do you mean by the first date of the week? Do you need to compute the date of the first day of the week? – Anton May 30 '11 at 22:12
  • You gave the correct answer twice, for which you get an upvote next to the answer mark :D I want to know the exact NSDate at which the week in my locale starts. That's answered (though not checked) in the other question. The code you give above gives the numeric index of the starting weekday, which is actually a more adequate answer to how I wrote my question, although I was looking for that other thing. Found it, thanks! – epologee May 30 '11 at 22:20
  • 1
    @Anton I think there is a mistake. According to the Apple documentation [link](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/DatesAndTimes/Articles/dtCalendars.html) `[[NSLocale currentLocale] objectForKey:NSLocaleCalendar];` returns `NSCalendar` not an id for calendar. – Apan Aug 26 '14 at 07:07
0

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.

Denis Hennessy
  • 7,243
  • 4
  • 25
  • 31
  • The answer was correct, but the code was wrong. @Apan already spotted it in 2014 but I didn't see the comment until now. I edited the original answer, the `firstWeekDay` method was the method asked for. – epologee May 22 '15 at 10:54