简体   繁体   中英

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

HaveYou tried?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM