I am trying to combine the time value (hours, minutes, seconds) of one NSDate with the date value (day, month, year) of a second NSDate with this m
Swift 3 extension:
func combineDateAndTime(date: Date, time: Date) -> Date {
let calendar = NSCalendar.current
let dateComponents = calendar.dateComponents([.year, .month, .day], from: date)
let timeComponents = calendar.dateComponents([.hour, .minute, .second], from: time)
var components = DateComponents()
components.year = dateComponents.year
components.month = dateComponents.month
components.day = dateComponents.day
components.hour = timeComponents.hour
components.minute = timeComponents.minute
components.second = timeComponents.second
return calendar.date(from: components)!
}