1.String.format("%02d", 5);-->结果:05
0代表前面要补的字符
2代表字符串长度
d表示参数为整数类型
2.秒转换成时分秒
private String secToTime(int time){
String timeStr = null;
int hour = 0;
int minute = 0;
int second = 0;
if (time <= 0)
return "00:00";
else {
minute = time / 60;
if (minute < 60) {
second = time % 60;
timeStr = String.format("%02d", minute) + ":" + String.format("%02d", second);
} else {
hour = minute / 60;
if (hour > 99)
return "99:59:59";
minute = minute % 60;
second = time - hour * 3600 - minute * 60;
timeStr = String.format("%02d", hour) + ":" + String.format("%02d", minute) + ":" + String.format("%02d", second);
}
}
return timeStr;
}