如何在 UITableView 的列表中获取一年中的所有月份。我想在一个数组中获取一年中的所有月份,以便我可以在表格视图中显示它。我这样做是为了获得一周的日期。
NSCalendar* calendar = [NSCalendar currentCalendar];// Init calendar
NSDateComponents* comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate: date]; // Get necessary date components
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE, dd"];
// Week days change from 1 to 7, Sunday is the 1st, Saturday - the last one.
for (int i = 1; i <= 7; i++){
[comps setWeekday:i];
NSDate *tDate = [calendar dateFromComponents:comps];
// NSString *day=[dateFormatter stringFromDate:tDate];
[self.mArrDates addObject:tDate];
}
NSLog(@"dates for week%@", self.mArrDates);