如何获得前一周的几天?例如 - 今天是 wed/04/2013,如果一周的第一天是星期天,这是一周的第四天。我需要带有'sunday/25/2013'、mon/26/2013、..... sat/31/2013 的数组?我正在这样做,但它没有工作需要帮助..
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 setDay:2]; // 1: sunday
[currentComps setWeek: [currentComps week] - 1];
NSLog(@"currentComps setWeek:>>>>>> %@", currentComps);
NSDate *firstDayOfTheWeek = [myCalendar dateFromComponents:currentComps];
NSLog(@"firstDayOfTheWeek>>>>>> %@", firstDayOfTheWeek);
NSString *firstStr = [myDateFormatter stringFromDate:firstDayOfTheWeek];
lbl_Day1.text = firstStr;