将毫秒转换为分钟和秒? [英] Converting Milliseconds to Minutes and Seconds?
本文介绍了将毫秒转换为分钟和秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我查看过以前的问题,但没有人得到我想要的答案。
如何将StopWatch方法的毫秒转换为分钟和秒?
我有:
I have looked through previous questions, but none had the answer I was looking for. How do I convert milliseconds from a StopWatch method to Minutes and Seconds? I have:
watch.start();
启动秒表和
watch.stop();
停止观看。我后来有
watch.getTime();
返回毫秒。我希望它能在秒和分钟内返回。我该怎么做呢? 我正在寻找一种方法来实现它,而不是乘以/除以1000,而是一种方法,可以使整个计算更具可读性,更不容易出错。
which returns Milliseconds. I want it to return in Seconds and Minutes. How do I go about doing so? I'm looking for a way to do it without multiplying/dividing by 1000 but rather a method that will make the whole computation more readable and less error-prone.
推荐答案
我建议使用 TimeUnit
。您可以这样使用它:
I would suggest using TimeUnit
. You can use it like this:
long minutes = TimeUnit.MILLISECONDS.toMinutes(millis);
long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);
这篇关于将毫秒转换为分钟和秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文