// 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格式化NSTimeInterval
我怎麼會輸出00:00.00,並將它增加一個第二的每第100,而不是第二個10?
使所述第一和第三格式說明符像你的第二個。 '%02u'。 – rmaddy
而這將是百分之一秒,而不是毫秒。毫秒需要三位小數。多個乘以100,而不是10. – rmaddy
對於毫秒,您需要將小數乘以1000.並使用'%03u'。 –