简体   繁体   English

如何比较两次毫秒精度?

[英]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. 我有一个字幕文本文件,该文件可以使用标准格式srt格式00:00:00,000时,分,秒,毫秒。

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? NSTimeInterval,NSDate? I think the best is to convert all to times to milliseconds number and compare. 我认为最好是将所有时间转换为毫秒数并进行比较。 But NSTimeInterval works with seconds, not milliseconds. 但是NSTimeInterval可以用秒而不是毫秒来工作。

Some clue? 有一些线索吗?

Marcos 马科斯

NSTimeInterval is likely what you want. NSTimeInterval可能是您想要的。 NSTimeInterval is in units of seconds, but has a fractional portion which can represent sub-millisecond values (it's typedef'ed to a double). NSTimeInterval以秒为单位,但是有一个小数部分,可以表示亚毫秒级的值(类型定义为双精度)。 Thus a value of 2.5 represents 2 seconds + 500ms. 因此,值2.5表示2秒+ 500毫秒。

In fact, NSTimer uses NSTimeInterval 实际上, NSTimer使用NSTimeInterval

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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