public class CommonUtil { private static final int HOUR_SECOND = 60 * 60; private static final int MINUTE_SECOND = 60; public static String getTimeStrBySecond(long second) { if (second <= 0) { return "00:00:00"; } StringBuilder sb = new StringBuilder(); long hours = second / HOUR_SECOND; if (hours > 0) { second -= hours * HOUR_SECOND; } long minutes = second / MINUTE_SECOND; if (minutes > 0) { second -= minutes * MINUTE_SECOND; } return (hours >= 10 ? (hours "") : ("0" hours) ":" (minutes >= 10 ? (minutes "") : ("0" minutes)) ":" (second >= 10 ? (second "") : ("0" second))); } },我来为大家科普一下关于java的单位转换算法?下面希望有你要的答案,我们一起来看看吧!

java的单位转换算法(Java单位转换之秒转)

java的单位转换算法

public class CommonUtil { private static final int HOUR_SECOND = 60 * 60; private static final int MINUTE_SECOND = 60; public static String getTimeStrBySecond(long second) { if (second <= 0) { return "00:00:00"; } StringBuilder sb = new StringBuilder(); long hours = second / HOUR_SECOND; if (hours > 0) { second -= hours * HOUR_SECOND; } long minutes = second / MINUTE_SECOND; if (minutes > 0) { second -= minutes * MINUTE_SECOND; } return (hours >= 10 ? (hours "") : ("0" hours) ":" (minutes >= 10 ? (minutes "") : ("0" minutes)) ":" (second >= 10 ? (second "") : ("0" second))); } }

,