开发者

How to compare two times in milliseconds precision?

开发者 https://www.devze.com 2022-12-27 18:49 出处:网络
I have a subtitle text file that works with standart srt format 00:00:00,000 Hour, minutes, seconds, milliseconds.

I have a subtitle text file that works with standart srt format 00:00:00,000 Hour, minutes, seconds, milliseconds.

I want to create a timer to update the subtitle screen and check the current time to know what subtitle show on screen.

Which is the best to开发者_JAVA技巧 use? NSTimeInterval, NSDate? I think the best is to convert all to times to milliseconds number and compare. But NSTimeInterval works with seconds, not milliseconds.

Some clue?

Marcos


NSTimeInterval is likely what you want. NSTimeInterval is in units of seconds, but has a fractional portion which can represent sub-millisecond values (it's typedef'ed to a double). Thus a value of 2.5 represents 2 seconds + 500ms.

In fact, NSTimer uses NSTimeInterval

+ (NSTimer*)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds
                                invocation:(NSInvocation*)invocation
                                   repeats:(BOOL)repeats;
0

精彩评论

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

关注公众号