美文网首页
根据当前日期获取当前日期所在的周数以及本周所有日期的数组

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

作者: 小彭1013 | 来源:发表于2016-11-14 11:41 被阅读73次

    -(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周
    }

    相关文章

      网友评论

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

          本文链接:https://www.haomeiwen.com/subject/gljhpttx.html