The most reliable way to get the next occurrence of a time is nextDate(after:matching:matchingPolicy:
of Calendar
because it considers also daylight saving changes.
assuming datePicker
is the NSDatePicker
instance:
let date = datePicker.date
let calendar = Calendar.current
// get hour and minute components of the given date
let components = calendar.dateComponents([.hour, .minute], from: date)
// calculate the next occurrence of the date components from now
let nextOccurrence = calendar.nextDate(after: Date(), matching: components, matchingPolicy: .nextTime)
solved Add 1 Day to a Date [closed]