I'm working on a counter, and this is my code to find the time.
NSDate *start = [NSDate date];
NSTimeInterval timeInterval = [start timeIntervalSinceDate:start];
NSLog(@"%f",timeInterval);
This is what it returns over and over again.
2014-03-08 17:59:46.834 Time[67444:303] 0.000000
What is happening with this?
You are using timeIntervalSinceNow
on an object that represents a very very close value to "now". Since you print in float, the value is rounded down to lower precision and you get 0.
Are you sure you didn't mean timeIntervalSince1970
?
NSTimeInterval
is defined as a double
. If you need precision above float, try printing as double using %ld
. If you need even more precision, look into mach_absolute_time()
.