獲得一個月后 的日期 該如何實現(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);