문제

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().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top