将 NSTimeInterval 格式设置为分钟:秒:毫秒
谁能告诉我如何在这段代码中显示毫秒?
-(void)updateViewForPlayerInfo:(AVAudioPlayer*)p {
countdownTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateTimeLeft)userInfo:p repeats:YES];
}
- (void)updateTimeLeft {
NSTimeInterval timeLeft = player.duration - player.currentTime;
int min=timeLeft / 60;
int sec=lroundf(timeLeft) % 60;
durationLabel.text = [NSString stringWithFormat:@"-%02d:%02d",min,sec,nil];
}
Can anyone please tell me how to display milliseconds in this piece of code?
-(void)updateViewForPlayerInfo:(AVAudioPlayer*)p {
countdownTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateTimeLeft)userInfo:p repeats:YES];
}
- (void)updateTimeLeft {
NSTimeInterval timeLeft = player.duration - player.currentTime;
int min=timeLeft / 60;
int sec=lroundf(timeLeft) % 60;
durationLabel.text = [NSString stringWithFormat:@"-%02d:%02d",min,sec,nil];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果有人想要将毫秒设置为最大 60,则将此行编辑
为
If any wants milliseconds to max 60 than edit this line
to
我不明白。您不需要为毫秒创建一个新变量吗?
I don't understand. Don't you just have to create a new variable for the milliseconds?
我认为这是最简单的解决方案:
将时间格式化为 MM:SS.sss 。如果您确实希望将其设置为
MM:SS:sss
(我不推荐),您可以这样做:请注意
stringWithFormat:
不需要nil
在其参数列表的末尾。I think this is the simplest solution:
That formats the time as
MM:SS.sss
. If you really want it asMM:SS:sss
(which I don't recommend), you can do this:Note that
stringWithFormat:
does not requirenil
at the end of its argument list.