开发者

timestamp and subtract objective C

开发者 https://www.devze.com 2023-01-20 19:22 出处:网络
I need to find the specific time a tap happens and then开发者_开发技巧 the time since it has passed.I have the app counting taps, I just haven\'t figured out the time thing.

I need to find the specific time a tap happens and then开发者_开发技巧 the time since it has passed. I have the app counting taps, I just haven't figured out the time thing.

I tried:

timeStamp = [[NSDate date] timeIntervalSince1970]; 

but I'm new to obj c and clearly there is a syntax problem.

Thanks for anyhelp.


If you are trying to find the amount of time that has passed since an event, I would create an NSDate time stamp when that event occurrs:

NSDate *timestamp = [NSDate date];

Then, later on to check how long it has been since that timestamp you can call:

NSTimeInterval interval = [timestamp timeIntervalSinceNow];

NSTimeInterval is just a typedef. It is actually a double representing a number of seconds. In the above case interval will be the number of seconds since the timestamp. (Also note that it will be negative since your timestamp is in the past.)


The most obvious reason I see for a syntax error would be the declaration of timeStamp.

It should be:

NSTimeInterval timeStamp;
0

精彩评论

暂无评论...
验证码 换一张
取 消