Calendar

public extension Calendar
  • SwifterSwift: Return the number of days in the month for a specified ‘Date’.

    let date = Date() // "Jan 12, 2017, 7:07 PM"
    Calendar.current.numberOfDaysInMonth(for: date) -> 31
    

    Declaration

    Swift

    func numberOfDaysInMonth(for date: Date) -> Int

    Parameters

    date

    the date form which the number of days in month is calculated.

    Return Value

    The number of days in the month of ‘Date’.