实用小函数
1.把milliseconds转为hh:mm:ss
View Code
1 public static String formatMillisecondsToString(long millisecond) { 2 int hour = 0; 3 int minute = 0; 4 5 int second = (int) millisecond / 1000; 6 if (second >= 60) { 7 minute = second / 60; 8 second = second % 60; 9 } 10 if (minute >= 60) { 11 hour = minute / 60; 12 minute = minute % 60; 13 } 14 15 String sHour = hour < 10 ? "0" + hour : "" + hour; 16 String sMinute = minute < 10 ? "0" + minute : "" + minute; 17 String sSecond = second < 10 ? "0" + second : "" + second; 18 19 if (hour > 0) { 20 return sHour + ":" + sMinute + ":" + sSecond; 21 } else { 22 return sMinute + ":" + sSecond; 23 } 24 }