Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-c get day of week in number starting with Monday, NOT Sunday

I'm making my custom calendar view for an app for the European market. In a function I should get number of day of week... I do, but it returns the number of the day of week starting with Sunday. How should I hardcode returning this number starting with Monday? Thanks Here is what I have so far:

-(int)getWeekDay:(NSDate*)date_
{
    NSLocale *frLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"fr_FR"];

    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    [gregorian setLocale:frLocale];
    NSDateComponents *comps = [gregorian components:NSWeekdayCalendarUnit fromDate:date_];
    int weekday = [comps weekday];

    NSLog(@"Week day is %i", weekday);
    return weekday;

}
like image 244
Vladimir Stazhilov Avatar asked Dec 12 '22 04:12

Vladimir Stazhilov


1 Answers

You should use [NSCalendar setFirstWeekday:] to do this.

like image 50
Joshua Weinberg Avatar answered May 12 '23 07:05

Joshua Weinberg