开发者

Objective C : calculate and display time to millisecond

Full Disclosure: I am a mathematical moron

int hours = totalSeconds / (60 * 60);
int minutes = (totalSeconds / 60) % 60;
int seconds = totalSeconds % 60;
//int milliseconds ???
calculatedExposureTime.text = [NSString stringWithFormat:@"%02d:%02d:%02d:%02d", hours, minutes, seconds, milliseconds];

Say totalSeconds was 开发者_StackOverflow中文版a fraction of a second (0.000156), how do I calculate and display time down to the millisecond?


...
double seconds = fmod(totalSeconds, 60.0);
... [NSString stringWithFormat:@"%02d:%02d:%06.3f", hours, minutes, seconds];

BTW, 0.000156 is less than one millisecond, so it will display as 0.000.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜