1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| /** * 时长转字符 * @param mDuration 时长(毫秒) * @param isMillisecond 是否需要毫秒,true:需要,false:不用 * @return */ public static String getTimeDurationString(@NonNull Long mDuration, @NonNull Boolean isMillisecond) { Long hours = 0L, minutes = 0L, seconds = 0L, millisecond = null; if (isMillisecond) { //毫秒 millisecond = mDuration % TimeConstants.SEC; } hours = mDuration / TimeConstants.HOUR; minutes = (mDuration / TimeConstants.MIN)-(hours*60); seconds = (mDuration / TimeConstants.SEC)-(minutes*60)-(hours*3600); String str_duration = getTimeString(hours, minutes, seconds, millisecond); return str_duration; }
private static String getTimeString(@NonNull Long hours, @NonNull Long minutes, @NonNull Long seconds, Long millisecond) { if (millisecond != null) { return String.format("%02d:%02d:%02d.%02d", hours, minutes, seconds, millisecond); } else { return String.format("%02d:%02d:%02d", hours, minutes, seconds); } }
|