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)));
}
}
,我来为大家科普一下关于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)));
}
}
免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com