-3

I need find the weeks list between 2 dates. I have startdate and enddate and the startdate might be any day(eg.Tuesday or Friday) for that start week, and the end date also the same like any day for the end week. how do i find the weeks list.please help me to do this.

4

1 回答 1

0

Use NSDateComponents against the current calendar specifying the fromDate and toDate and a components flag os NSWeekCalendarUnit. Then the week property of the returned NSDateComponents object will be the number of weeks between the two dates, e.g.:

    NSCalendar *currentCalendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [currentCalendar components:NSWeekCalendarUnit
                                                      fromDate:firstDate
                                                        toDate:secondDate options:0];

    NSInteger weeks = components.week;

where 'firstDate' and 'secondDate' are NSDate objects.

于 2012-09-19T12:39:42.183 回答