I have two date first get from DatePicker (self.datePicker.date
) and another is manually set NSDate
(self.fireDate
).
I want to add time of self.datePicker.date
to self.fireDate
.
My Logic is: I Follow this Question
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);
Please give me any suggestion on this issue.
Thanks in advance ;)