You can use the nextDateAfterDate: method on an nextDateAfterDate: object to achieve this,
let now = Date()
Here is an easy way to find next Monday. If today is Monday, the next function returns today, or the next next Monday. Note that it uses en_POSIX_US , so that days can be matched. When the locale is ru_POSIX_US , the characters of the day of the week become,
["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
And this is how you can use these days,
func findNext(_ day: String, afterDate date: Date) -> Date? { var calendar = Calendar.current calendar.locale = Locale(identifier: "en_US_POSIX") let weekDaySymbols = calendar.weekdaySymbols let indexOfDay = weekDaySymbols.index(of: day) assert(indexOfDay != nil, "day passed should be one of \(weekDaySymbols), invalid day: \(day)") let weekDay = indexOfDay! + 1 let components = calendar.component(.weekday, from: date) if components == weekDay { return date } var matchingComponents = DateComponents() matchingComponents.weekday = weekDay // Monday let nextDay = calendar.nextDate(after: date, matching: matchingComponents, matchingPolicy:.nextTime) return nextDay! } let nextMonday = findNext("Monday", afterDate: Date()) let mondayAfterThat = findNext("Monday", afterDate: nextMonday!) let thursday = findNext("Thursday", afterDate: mondayAfterThat!)
Sandeep
source share