https://www.cnblogs.com/SUPER-F/p/7298548.html
正数为后 负数为前
-(NSDate *)getPriousorLaterDateFromDate:(NSDate *)date withMonth:(NSInteger)month
{
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setMonth:month];
NSCalendar *calender = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDate *mDate = [calender dateByAddingComponents:comps toDate:date options:0];
return mDate;
}
博客给出了一个获取指定日期前后月份日期的代码示例。通过定义一个方法,传入日期和月份数,利用NSDateComponents和NSCalendar进行计算,最终返回计算后的日期。
2200

被折叠的 条评论
为什么被折叠?



