Here is the code:
let components = DateComponents(year: 2022,month: 9,weekOfMonth: 3)
let date = Calendar.autoupdatingCurrent.date(from: components)!
let formatter = DateFormatter()
formatter.dateStyle = .long
formatter.timeStyle = .none
print(formatter.string(from: date))
Here is output:
September 1, 2022
But the correct answer should be September 11, 2022. Why? Is this a bug or I just missed something?
This method will create a date for start of the given year, month and week in month. This will return nil if the start of the week is not in the month specified:
Most of the code should be self explanatory.
Testing:
Output: