int类型转换成String , 不足n位 在前面补0
1.String.format("%02d", 5);-->结果:05
0代表前面要补的字符
2代表字符串长度
d表示参数为整数类型
2.秒转换成时分秒
1 private String secToTime(int time){ 2 String timeStr = null; 3 int hour = 0; 4 int minute = 0; 5 int second = 0; 6 if (time <= 0) 7 return "00:00"; 8 else { 9 minute = time / 60; 10 if (minute < 60) { 11 second = time % 60; 12 timeStr = String.format("%02d", minute) + ":" + String.format("%02d", second); 13 } else { 14 hour = minute / 60; 15 if (hour > 99) 16 return "99:59:59"; 17 minute = minute % 60; 18 second = time - hour * 3600 - minute * 60; 19 timeStr = String.format("%02d", hour) + ":" + String.format("%02d", minute) + ":" + String.format("%02d", second); 20 } 21 } 22 return timeStr; 23 }