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
.
精彩评论