Ronn
Ronn

Reputation: 1773

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 a fraction of a second (0.000156), how do I calculate and display time down to the millisecond?

Upvotes: 0

Views: 1038

Answers (1)

Marcelo Cantos
Marcelo Cantos

Reputation: 185862

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

Upvotes: 1

Related Questions