Here is the solution to get the name of the day of the week of the first day in the current month
NSDateComponents *weekdayComps = [[NSDateComponents alloc] init]; weekdayComps = [calendar.currentCalendar components:calendar.unitFlags fromDate:calendar.today]; weekdayComps.day = 1; NSDateFormatter *weekDayFormatter = [[NSDateFormatter alloc]init]; [weekDayFormatter setDateFormat:@"EEEE"]; NSString *firstweekday = [weekDayFormatter stringFromDate:[calendar.currentCalendar dateFromComponents:weekdayComps]]; NSLog(@"FIRST WEEKDAY: %@", firstweekday);
For week week index use this
NSDate *weekDate = [calendar.currentCalendar dateFromComponents:weekdayComps]; NSDateComponents *components = [calendar.currentCalendar components: NSWeekdayCalendarUnit fromDate: weekDate]; NSUInteger weekdayIndex = [components weekday]; NSLog(@"WEEKDAY INDEX %i", weekdayIndex);
If necessary, you can increase or decrease the month.
Anton source share