我有两个日期首先从 DatePicker ( self.datePicker.date
) 获取,另一个是手动设置的NSDate
( self.fireDate
)。
我想添加self.datePicker.date
时间self.fireDate
。
我的逻辑是:我关注这个问题
NSCalendar *currentCalender = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *timeComponents = [currentCalender components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:[self.datePicker date]];
NSDateComponents *dateComponents = [currentCalender components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate: self.fireDate];
[dateComponents setHour:timeComponents.hour];
[dateComponents setMinute:timeComponents.minute];
[dateComponents setSecond:timeComponents.second];
NSDate *finalDate = [currentCalender dateFromComponents:dateComponents];
NSLog(@"%@", [self.datePicker date]);
NSLog(@"%@", finalDate);
NSLog(@"%@", self.fireDate);
请就这个问题给我任何建议。
提前致谢 ;)