Search code examples
iosnsdatenstimeinterval

How accurate is NSTimeInterval


I am trying to get the time difference between two NSDates.

NSDate *d1 = somedate;
NSDate *d2 = someOtherdate;
NSTimeInterval sec = [d2 timeIntervalSinceDate:d1];

How accurate is NSTimeInterval? Does it take care of the variation in number of days in a month, for example if the number of days is 28,29,30 or 31? Also time zone difference?


Solution

  • How accurate is NSTimeInterval?

    It's accurate to milliseconds (if not more).

    Does it take care of the variation in number of days in a month, for example if the number of days is 28,29,30 or 31?

    Yes, the difference will be in seconds. NSDate deals with actual days in a month as well as leap years and daylight savings, etc.

    Also time zone difference?

    NSDate values are always stored in UTC so your NSDate objects are always in the same timezone. There is nothing to deal with for this.