开发者

Objective C : calculate and display time to millisecond

开发者 https://www.devze.com 2023-01-12 13:23 出处:网络
Full Disclosure: I am a mathematical moron int hours = totalSeconds / (60 * 60); int minutes = (totalSeconds / 60) % 60;

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

精彩评论

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