Swift-Calendar Extension
2018-05-15 本文已影响0人
长风浮云
获取某个月的天数
extension Calendar {
/// let date = Date() // "Jan 12, 2017, 7:07 PM"
/// Calendar.current.numberOfDaysInMonth(for: date) -> 31
///
/// - Parameter date: the date form which the number of days in month is calculated.
/// - Returns: The number of days in the month of 'Date'.
public func numberOfDaysInMonth(for date: Date) -> Int {
return range(of: .day, in: .month, for: date)!.count
}
}
资源来自网络和日常整理,持续更新