Adding days to NSDate

后端 未结 9 1836
广开言路
广开言路 2021-01-02 04:34

I want add days to a date, I got many codes for this but none of them are working for me below shown is my code,please somebody help me to fix this issue

int         


        
9条回答
  •  余生分开走
    2021-01-02 05:09

    In Swift 2, use extension to extend NSDate:

    extension NSDate {
    
        func addDays(days:Int) -> NSDate{
            let newDate = NSCalendar.currentCalendar().dateByAddingUnit(
                .Day,
                value: days,
                toDate: self,
                options: NSCalendarOptions(rawValue: 0))
    
            return newDate!
        }
    }
    

提交回复
热议问题