現在の週の日の配列を取得するにはどうすればよいですか?
たとえば、今日は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 があります。