当前位置: 编程技术>java/j2ee
java整数(秒数)转换为时分秒格式的示例
来源: 互联网 发布时间:2014-11-05
本文导语: 整数(秒数)转换为时分秒格式(xx:xx:xx) 代码如下:// a integer to xx:xx:xx public static String secToTime(int time) { String timeStr = null; int hour = 0; int minute = 0; int second = 0; if (time 99) ...
整数(秒数)转换为时分秒格式(xx:xx:xx)
代码如下:
// a integer to xx:xx:xx
public static String secToTime(int time) {
String timeStr = null;
int hour = 0;
int minute = 0;
int second = 0;
if (time 99)
return "99:59:59";
minute = minute % 60;
second = time - hour * 3600 - minute * 60;
timeStr = unitFormat(hour) + ":" + unitFormat(minute) + ":" + unitFormat(second);
}
}
return timeStr;
}
public static String unitFormat(int i) {
String retStr = null;
if (i >= 0 && i < 10)
retStr = "0" + Integer.toString(i);
else
retStr = "" + i;
return retStr;
}