开发者

how can I store different times from stopwatch

开发者 https://www.devze.com 2023-03-09 04:43 出处:网络
I am confused regarding to calculation of two different times. In my game, when game starts then timer gets started (like stop watch) and it stops when game gets finished. Now I have to store be开发者

I am confused regarding to calculation of two different times. In my game, when game starts then timer gets started (like stop watch) and it stops when game gets finished. Now I have to store be开发者_运维问答st low time among previous time list.

I am getting time in hh:mm:ss format. how can I store this time so that i can compare it with different time in list ? I tried to store this value in NSString, but the comparison fails.

EDITED :

Let me clarify the Question :

For example how can I store different times from stopwatch and how to sort it in ascending order ?

any suggestions?

Thanks...


Take two NSDates, one at the game start and one at game finish, then calculate the difference.

NSDate *startDate = [NSDate date]; // At game start

NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:startDate]; // At game finish

NSlog(@"interval: %.2f", interval);


You could use

long stamp =  (long)[[NSDate date] timeIntervalSince1970];

for each of your time-relevant situation since the posted code is giving you a UNIX-timestamp. This timestamp can be used in arithmetic operations/comparisons which should be exact what you are looking for.

0

精彩评论

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