How do I find the number of days in given month and year using swift

后端 未结 8 656
庸人自扰
庸人自扰 2020-12-05 04:06

I want to find the total number days on given month and year. Example: I want to find total number of days on year = 2015, month = 7

8条回答
  •  难免孤独
    2020-12-05 04:28

    What about for a given year?

    The following is printing the number of days in the date's month:

    let range = userCalendar.range(of: .day, in: .year, for: Date())!
    print("Days In Year: \(range.count)") // prints 31
    

    ... and not the number of days in the date's year as expected :/

提交回复
热议问题