Subtract 7 days from current date

前端 未结 11 919
灰色年华
灰色年华 2021-01-29 22:41

It seems that I can\'t subtract 7 days from the current date. This is how i am doing it:

NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:N         


        
11条回答
  •  遥遥无期
    2021-01-29 23:31

    FOR SWIFT 3.0

    here is fucntion , you can reduce days , month ,day by any count like for example here , i have reduced the current system date's year by 100 year , you can do it for day , month also just set the counter and store it in an array , you can this array anywhere then func currentTime()

     {
    
        let date = Date()
        let calendar = Calendar.current
        var year = calendar.component(.year, from: date)
        let month = calendar.component(.month, from: date)
        let  day = calendar.component(.day, from: date)
        let pastyear = year - 100
        var someInts = [Int]()
        printLog(msg: "\(day):\(month):\(year)" )
    
        for _ in pastyear...year        {
            year -= 1
                         print("\(year) ")
            someInts.append(year)
        }
              print(someInts)
            }
    

提交回复
热议问题