如何获得当前一周的几天?
例如 - 今天是saturday - 28 july
.
我需要带有'28 Saturday'的数组27 Friday
,,,,26 Thursday
... 25 Wednesday
?22 Sunday
[代码] NSCalendar *myCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *currentComps = [myCalendar components:( NSYearCalendarUnit | NSMonthCalendarUnit | NSWeekOfYearCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:weekDate];
int ff = currentComps.weekOfYear;
NSLog(@"1 %d", ff);
[currentComps setWeekday:1]; // 1: sunday
NSDate *firstDayOfTheWeek = [myCalendar dateFromComponents:currentComps];
[currentComps setWeekday:7]; // 7: saturday
NSDate *lastDayOfTheWeek = [myCalendar dateFromComponents:currentComps];
NSLog(@"first - %@ \nlast - %@", firstDayOfTheWeek, lastDayOfTheWeek); [code]
我这样做了,但我有 'firstDayOfWeek' - 2012-07-29 和 'lastDayOfWeek' - 2012-08-04