// calculate elapsed time
NSTimeInterval elapsed = currentTime - startTime;
int mins = (int) (elapsed / 60.0);
elapsed -= mins * 60;
int secs = (int) (elapsed);
elapsed -= secs;
int fraction = elapsed * 10.0;
// update time label using format 0:00:0
returnTimeString = [NSString stringWithFormat:@"%u:%02u.%u",mins,secs,fraction];这目前输出0:00.0。
我如何输出00:00.00,并让它每百分之一秒而不是十分之一秒递增?
发布于 2014-02-22 01:40:50
returnTimeString = [NSString stringWithFormat:@"%02u:%05.2f",
(int)(elapsed/60), fmod(elapsed, 60)];发布于 2014-02-22 01:28:22
您可以在格式说明符中使用0n对显示给n数字的数字长度进行零填充(其中n是正整数),例如,
unsigned int seconds = elapsed;
unsigned int hundredths = (elapsed - seconds) * 100.0;
[NSString stringWithFormat:@"%02u:%02u.%02u", (seconds/60), (seconds%60), hundredths]https://stackoverflow.com/questions/21948333
复制相似问题