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
You need to create an NSCalendar and then get the date components from the first and second dates and then get the date using the new date components from the NSCalendar.
Use the NSCalendar methods
– components:fromDate:
– dateFromComponents:
and the corresponding unit flags
NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit |NSSecondCalendarUnit;