In my application i have to show list of working hours by date in a table view,
Here i have 5 scenarios
You can use this for getting current year & month. Simply add these to previous answer as my friend had suggested.
NSInteger year = [comps year];
NSInteger month = [comps month];
Now, I think if you're getting current year & month, you can set manually for 1st date. and perform as you want.
Main thing is to get weekday .. Thanks.
I hope this will give you basic idea how you have to proceed: For other scenarios you can work out
- (NSDate *)firstDayOfWeekFromDate:(NSDate *)date {
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDateComponents* comps = [calendar components:NSYearForWeekOfYearCalendarUnit |NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:date];
[comps setWeekday:2]; // 2: monday
return [calendar dateFromComponents:comps];
}