格式化NSTimeInterval

阿波罗
// 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,并使其每百分之一秒而不是百分之一秒增加一次?

抢马约夫
returnTimeString = [NSString stringWithFormat:@"%02u:%05.2f",
    (int)(elapsed/60), fmod(elapsed, 60)];

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章