我想讓這個字符串返回Minute:Second:Millisecond for my MediaPlayer。我已經找到這個代碼,但不知道如何使毫秒工作,並把它放在小數點後兩位。我相信它對於合適的人來說簡單!獲取毫秒格式
private String getTimeString(long millis) {
StringBuffer buf = new StringBuffer();
int hours = (int) (millis/(1000*60*60));
int minutes = (int) ((millis % (1000*60*60))/(1000*60));
int seconds = (int) (((millis % (1000*60*60)) % (1000*60))/1000);
buf
.append(String.format("%02d", hours))
.append(":")
.append(String.format("%02d", minutes))
.append(":")
.append(String.format("%02d", seconds));
return buf.toString();
}
感謝你們總是
也許你應該看看[Formatter](http://download.oracle.com/javase/1.5.0/docs/api /java/util/Formatter.html)? – kylc