次の方法で計算された変数 currTime があります。
long currTime = System.currentTimeMillis() - start; //where start is the start time of whatever I'm timing
これを次のような表示用の文字列に変換するにはどうすればよいですか。
12544 は「00:12.54」と表示されます
67855 は「01:07.86」と表示されます
…などなど…?
3 桁のミリ秒の解決策は非常に簡単です。
public String formatDuration(long elapsedTimeMillis) {
SimpleDateFormat df = new java.text.SimpleDateFormat("mm:ss.SSS");
df.setTimeZone(TimeZone.getTimeZone("UTC")); // Epoch is UTC
return df.format(new Date(elapsedTimeMillis));
}
2 桁のミリ秒の場合、Joda Time フォーマッタを使用するか、文字列から最後の桁を削除するか、手動で解決する必要があります。