NSDate of yesterday

后端 未结 6 1455
孤独总比滥情好
孤独总比滥情好 2020-11-30 01:59

How do I create an NSDate object with a custom date other than the current date? For example I would like to create a var of yesterday or of 2 days ago.

6条回答
  •  甜味超标
    2020-11-30 02:23

    Please try below code. I think it's simple.

    let today = NSDate()
    let tomorrow = today.dateByAddingTimeInterval(24 * 60 * 60)
    let yesterday = today.dateByAddingTimeInterval(-24 * 60 * 60)
    

    Cheers!!!

提交回复
热议问题