#pragma mark - 获取当前月

#pragma mark - 获取当前月

- (NSString *)getMonth

{

NSDate *nowDate = [NSDate date];

NSCalendar *calendar = [NSCalendar currentCalendar];

NSDateComponents *comp = [calendar components: NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday | NSCalendarUnitDay fromDate:nowDate];

// 获取今天是几月

NSInteger month = [comp month];

// 获取今天是几年

NSInteger year = [comp year];

if(_NumM == 0)

{

}

else if(_NumM > 0)

{

month = month + _NumM;

if (month > 12) {

month = 1;

year = year + 1;

}

}

else

{

month = month + _NumM;

if (month < 1) {

month = 12;

year = year - 1;

}

}

//拼接日期

NSString *monthDay = [NSString stringWithFormat:@"%ld-%ld",year,month];

return monthDay;

}

你可能感兴趣的:(#pragma mark - 获取当前月)