Number of days in the current month using iOS?

前端 未结 4 627
走了就别回头了
走了就别回头了 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 01:58

    Swift syntax:

    let date = NSDate()
    let cal = NSCalendar(calendarIdentifier:NSCalendarIdentifierGregorian)!
    let days = cal.rangeOfUnit(.CalendarUnitDay, inUnit: .CalendarUnitMonth, forDate: date)
    

提交回复
热议问题