うんざりする
2 つの異なる datePicker があるように見えますか? 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];