Search code examples
iphoneobjective-cnsdatenscalendarnsdatecomponents

Get the weekday from a selected day and not from the current day


I've seen many ways to get the weekday, but none of them was from a selected day.

NSDate * selectedDate = _selectedDate //From Params

NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:[[NSDate alloc] init]];

NSInteger weekday = [components weekday];

How and where should I insert my selected Date?

Since [components setDay:(INTEGER REQUIRED)] is it a way to convert the selected day to the current day.. anyone got a clue on this?

Thank's


Solution

  • HaveYou tried?

    NSDateComponents *components = [cal components:NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:selectedDate];