[android]時間の長さをミリ秒から分と秒に変換

498 ワード

Android音楽プレーヤーアプリケーションでは、読み出した音楽の時間長はlongタイプでミリ秒数単位で、例えば234736を分と秒に変換するには03:55(四捨五入を含む)
public static String timeParse(long duration) {
	String time = "" ;
		
	long minute = duration / 60000 ;
	long seconds = duration % 60000 ;
	
	long second = Math.round((float)seconds/1000) ;
		
	if( minute < 10 ){
		time += "0" ;
	}
	time += minute+":" ; 
		
	if( second < 10 ){
		time += "0" ;
	}
	time += second ;
		
	return time ;
}