How to get all the days/dates in current week, this month, this year using the current date (today) in iPhone

后端 未结 2 674
日久生厌
日久生厌 2021-01-26 03:48

In my application i have to show list of working hours by date in a table view,

Here i have 5 scenarios

  1. Today\'s projects, working hours
  2. Selected
2条回答
  •  醉酒成梦
    2021-01-26 03:57

    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];
      }
    

提交回复
热议问题