I use this method to add a month to a date
- (NSDate *)sameDateByAddingMonths:(NSInteger)addMonths { NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents * components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:self]; [components setMonth:components.month + addMonths]; return [calendar dateFromComponents:components]; }
But when in the previous month in the independent NSDate there were more days than on the first day of the next month, it jumps, for example
June has 31 => I - June 31 Calling this sets the date to 1.August as July has 30 days
How to do it right? I thought it should behave "right" and the clip at the end of the month
source share