iOS Blog

calendar 计算几天后的某天

2015-12-29  本文已影响339人  ShawnDu
let now = NSDate()
let calendar = NSCalendar.currentCalendar()
let startComponents = calendar.components([NSCalendarUnit.Year,.Month,.Day,.Weekday], fromDate: now)
startComponents.day += 5
let weekendDate = calendar.dateFromComponents(startComponents);
print(weekendDate);
extension NSDate {
    func Year() -> Int {
        let calendar = NSCalendar.currentCalendar()
        let components = calendar.components(.Year, fromDate: self)
        return components.year
    }
    
    func Month() -> Int {
        let calendar = NSCalendar.currentCalendar()
        let components = calendar.components(.Month, fromDate: self)
        return components.month
    }
    
    func Day() -> Int {
        let calendar = NSCalendar.currentCalendar()
        let components = calendar.components(.Day, fromDate: self)
        return components.day
    }
    
    func WeekDay() -> Int {
        let calendar = NSCalendar.currentCalendar()
        let components = calendar.components(.Weekday, fromDate: self)
        return components.weekday
    }
    
    func first() -> Int {
        let calendar = NSCalendar.currentCalendar()
        let first = calendar.firstWeekday
        return first
    }
}

github 项目地址

上一篇下一篇

猜你喜欢

热点阅读