本文介紹了將毫秒轉換為分和秒?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我已經查看了以前的問題,但沒有一個答案是我想要的.如何將秒表方法中的毫秒轉換為分和秒?我有:
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);
這篇關于將毫秒轉換為分和秒?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!