How can I calculate the difference between two dates?

后端 未结 9 1359
渐次进展
渐次进展 2020-11-28 02:27

How can I calculate the days between 1 Jan 2010 and (for example) 3 Feb 2010?

9条回答
  •  孤城傲影
    2020-11-28 03:19

    NSTimeInterval diff = [date2 timeIntervalSinceDate:date1]; // in seconds
    

    where date1 and date2 are NSDate's.

    Also, note the definition of NSTimeInterval:

    typedef double NSTimeInterval;
    

提交回复
热议问题