简体   繁体   中英

How to compare two times in milliseconds precision?

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 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM