Difference between two NSDates

前端 未结 3 1100
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 05:54

I am taking two NSDates by using date time picker. Now I want to count the number of days between these two NSDates. How can I find the difference between two NSDates.

3条回答
  •  臣服心动
    2020-12-31 06:19

    Here's a Swift implementation (I use this all the time while debugging things like network requests and JSON parsing):

    let date1 = NSDate()
    
    // do some long running task
    
    let date2 = NSDate()
    print(date2.timeIntervalSinceDate(date1))
    
    // you can also do this in one line, of course:
    print(NSDate().timeIntervalSinceDate(date1))
    

提交回复
热议问题