畏缩
看起来您有两个不同的日期选择器? datePicker
和datePicker1
?那是怎么回事?
此外,这不会满足您的期望:
NSDate *newDate1 = [now dateByAddingTimeInterval:60*60*24*364];
那就是创建一个新的日期,它正好是未来 31,449,600 秒。除此之外,它没有做任何事情。
您想要做的是从当前日期中提取所有日期组件并将它们归零:
NSDate *now = [NSDate date];
NSDateComponents *nowComponents = [[NSCalendar currentCalendar] components:(NSEraCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:now];
// technically these next lines are unnecessary, since we only pulled out the era-year-month-day, but they're included here for understanding/completeness:
[nowComponents setHour:0];
[nowComponents setMinute:0];
[nowComponents setSecond:0];
// now we can turn it back into a date:
NSDate *todayAtMidnight = [[NSCalendar currentCalendar] dateFromComponents:nowComponents];