I want to get two dates, the first and last day of current month. Pretty simple. But date(bySetting: Calendar.Component, value: Int, of: Date) are not working properly.
Look this piece of code:
When Date() prints 2019-04-18 14:11:36 UTC
let calendar = Calendar.current
let firstDayDate = calendar.date(bySetting: .day, value: 1, to: Date())! //2019-05-01 03:00:00 UTC
let firsDayNextMonth = calendar.date(byAdding: .month, value: 1, to: firstDayDate)! //2019-06-01 03:00:00 UTC
let lastDayMonthDate = calendar.date(bySetting: .day, value: -1, to: firsDayNextMonth)! //2019-05-31 03:00:00 UTC
Run Code Online (Sandbox Code Playgroud)
Look at …