問題描述
我已經(jīng)查看了以前的問題,但沒有一個(gè)答案是我想要的.如何將秒表方法中的毫秒轉(zhuǎn)換為分和秒?我有:
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();
啟動(dòng)秒表和
watch.stop();
停止手表.我后來有
watch.getTime();
返回毫秒.我希望它在秒和分鐘內(nèi)返回.我該怎么做呢?我正在尋找一種無需乘以/除以 1000 的方法,而是一種使整個(gè)計(jì)算更具可讀性且不易出錯(cuò)的方法.
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);
這篇關(guān)于將毫秒轉(zhuǎn)換為分和秒?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!