美文网首页Swift
Swift-Calendar Extension

Swift-Calendar Extension

作者: 长风浮云 | 来源:发表于2018-05-15 11:32 被阅读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
    }
}

资源来自网络和日常整理,持续更新

相关文章

网友评论

    本文标题:Swift-Calendar Extension

    本文链接:https://www.haomeiwen.com/subject/fdyedftx.html