Number of days in the current month using iOS?

前端 未结 4 622
走了就别回头了
走了就别回头了 2020-12-05 01:23

How can I get the current number of days in the current month using NSDate or something similar in Cocoa touch?

4条回答
  •  清歌不尽
    2020-12-05 02:16

    Swift 3 syntax has changed a bit from Erez's answer:

    let cal = Calendar(identifier: .gregorian)
    let monthRange = cal.range(of: .day, in: .month, for: Date())!
    let daysInMonth = monthRange.count
    

提交回复
热议问题