I have NSDate* day1
and NSDate* day2
. How can I make a NSDate* day3
by copying only year/month/day from day1 and hour/minute/second from d
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *comps = [[NSCalendar currentCalendar] components:unitFlags fromDate:day1];
NSDate *day3 = [[NSCalendar currentCalendar] dateFromComponents:comps];
unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
comps = [[NSCalendar currentCalendar] components:unitFlags fromDate:day2];
day3 = [[NSCalendar currentCalendar] dateByAddingComponents:comps toDate:day3 options:0];
Sources: