Code example for TimeUnit

Methods: toMinutes, toSeconds

0
	@TargetApi(Build.VERSION_CODES.GINGERBREAD)
	public static String getReadableDuration(long duration) {
		String readableDuration = null;
		if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
			readableDuration = String.format("%02d min, %02d sec", 
					TimeUnit.MILLISECONDS.toMinutes(duration),
					TimeUnit.MILLISECONDS.toSeconds(duration) - 
					TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))
					); 
		} 
 
		else { 
			final int seconds = (int) (duration/1000) % 60;
			final int minutes = (int) ((duration / (1000*60)) % 60);
			final String secondsStr = seconds < 10 ? "0" + seconds : String.valueOf(seconds);
			readableDuration = minutes + ":" + secondsStr;
		} 
 
		return readableDuration;
	}