With Swift 3 and iOS 10, the easiest way to find this is Calendar dateInterval(of:for:) :
func monthInterval() -> DateInterval? { let calendar = Calendar.current guard let interval = calendar.dateInterval(of: .month, for: Date()) else { return nil } let duration = interval.duration // Subtract one second because dateInterval(of:for:) end date returns the beginning of the following month return DateInterval(start: interval.start, duration: duration - 1) } guard let interval = monthInterval() else { return }
Then you can use interval.start and interval.end to get the dates you need.
LuisCien May 09 '17 at 1:49 am 2017-05-09 01:49
source share