获得一个月后 的日期 该如何实现?
NSCalendar * calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];// 公立
NSDateComponents * components = [[NSDateComponents alloc]init];
[components setYear: 1];
[components setMonth: - 1];
[components setDay: 5]; //设置你需要增加或减少的年、月、日即可获得新的日期
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);
网友评论