根据当前日期获取当前日期所在的周数以及本周所有日期的数组

2016-11-14  本文已影响73人  小彭1013

-(void)fetcheArrayWithDate:(NSDate *)date{

NSDate *firstDayOfCurrentWeek = [DateCalculater firstWeekDayOftheDay:date];
NSDate *beginDate = [DateCalculater dateAfterWeeks:0 toDate:firstDayOfCurrentWeek];
NSMutableArray *weekDatesArray = [NSMutableArray array];

NSMutableArray *weekDaysArray = [NSMutableArray array];

for (NSInteger i = 0; i < 7; i++)
{
    NSDate *newDate = [DateCalculater dateAfterDays:i toDate:beginDate ];
    
    NSString *dateString = [DateCalculater stringFromDate:newDate];
    [weekDatesArray addObject:dateString];//日期格式2016-11-14
  
   NSInteger dateNumber = [DateCalculater dayNumberOftheDate:newDate];
    
    NSString *dayString = [NSString stringWithFormat:@"%ld",dateNumber];
    
    [weekDaysArray addObject:dayString];//14
    
}

NSInteger weekNumber = [DateCalculater weekNumberOftheDate:beginDate];//例如今天是47周
}

上一篇下一篇

猜你喜欢

热点阅读