extension Date {
func adding(minutes: Int) -> Date {
return Calendar.current.date(byAdding: .minute, value: minutes, to: self)!
}
func adding(hours: Int) -> Date {
return Calendar.current.date(byAdding: .hour, value: hours, to: self)!
}
func adding(days: Int) -> Date {
return Calendar.current.date(byAdding: .day, value: days, to: self)!
}
func adding(weaks: Int) -> Date {
return Calendar.current.date(byAdding: .day, value: weaks * 7, to: self)!
}
func adding(months: Int) -> Date {
return Calendar.current.date(byAdding: .month, value: months, to: self)!
}
func adding(years: Int) -> Date {
return Calendar.current.date(byAdding: .year, value: years, to: self)!
}
}
Использовать так:
let newDate = oldDate.adding(days: 5)