獲得一個(gè)月后 的日期 該如何實(shí)現(xiàn)?
NSCalendar * calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];// 公立
NSDateComponents * components = [[NSDateComponents alloc]init];
[components setYear: 1];
[components setMonth: - 1];
[components setDay: 5]; //設(shè)置你需要增加或減少的年、月、日即可獲得新的日期
NSDate * newData = [calendar dateByAddingComponents:components toDate:[NSDate date] options:0];
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"YY年MM月dd日"];
NSString * timeString = [dateFormatter stringFromDate:newData];
NSLog(@"更改后的日期是:%@", timeString);