1 工具方法
/**
* 将秒转为时分秒格式【01:01:01】
* @param second 需要转化的秒数
* @return
*/
public static String secondConvertHourMinSecond(Long second) {
String str = "00:00:00";
if (second == null || second < 0) {
return str;
}
// 得到小时
long h = second / 3600;
str = h > 0 ? ((h < 10 ? ("0" + h) : h) + ":") : "00:";
// 得到分钟
long m = (second % 3600) / 60;
str += (m < 10 ? ("0" + m) : m) + ":";
//得到剩余秒
long s = second % 60;
str += (s < 10 ? ("0" + s) : s);
return str;
}
2 调用
public static void main(String[] args) {
System.out.println(secondConvertHourMinSecond(Long.valueOf(3661)));
}
3 结果
说明:如果不足一小时,也会返回小时,不足一分钟也会返回分钟,也就是说:最后的格式不管怎么样都是时分秒的格式