java时间格式转化(毫秒 to 00:00)

把秒数转换为%d:%02d:%02d 格式

private String stringForTime(int timeSec) {
int totalSeconds = timeSec;
int seconds = totalSeconds % 60;
int minutes = totalSeconds / 60 % 60;
int hours = totalSeconds / 3600;
if (null!=mFormatBuilder){
this.mFormatBuilder.setLength(0);
}
return hours > 0 ? this.mFormatter.format("%d:%02d:%02d", new Object[]{Integer.valueOf(hours), Integer.valueOf(minutes), Integer.valueOf(seconds)}).toString() : this.mFormatter.format("%02d:%02d", new Object[]{Integer.valueOf(minutes), Integer.valueOf(seconds)}).toString();
}
原文地址:https://www.cnblogs.com/zhaoleigege/p/5892150.html