获取某年某月某日的时间date

//根据当前月获取

NSCalendar * calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

 NSDateComponents * components = [[NSDateComponents alloc]init];

//当前年加1

components.year=1;

//当前月加1

components.month=1;

//当前天加1

components.day=1;

NSDate * nextDate = [calendar dateByAddingComponents:components toDate:[NSDate date] options:NSCalendarWrapComponents];

//如果当前时间是2021-11-03,经过以上方法获取到的时间为2022-12-04

你可能感兴趣的:(获取某年某月某日的时间date)