Subtract 7 days from current date

前端 未结 11 1200
灰色年华
灰色年华 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:22

    Swift 3.0+ version of the original accepted answer

    Date().addingTimeInterval(-7 * 24 * 60 * 60)

    However, this uses absolute values only. Use calendar answers is probably more suitable in most cases.

提交回复
热议问题