首页 > 代码库 > 关于两个时间(00:00:00)相加的实现方法
关于两个时间(00:00:00)相加的实现方法
timeList={"00:20:00","00:23:43"};
public static String getTotal(String[] timeList) {
String timeString = null;int hour = 0;
int min = 0;
int sec = 0;
for (int i = 0; i < timeList.length; i++) {
timeString = timeList[i];
int firstIndex = timeString.indexOf(‘:‘);
int secondIndex = timeString.lastIndexOf(‘:‘);
hour += Integer.parseInt(timeString.substring(0, firstIndex));
min += Integer.parseInt(timeString.substring(firstIndex + 1,
secondIndex));
sec += Integer.parseInt(timeString.substring(secondIndex + 1,
timeString.length()));
}
int secToMin, sec2;
int minToHour, min2;
if (sec > 60) {
secToMin = (sec / 60);
sec2 = (sec % 60);
min = min + secToMin;
}
if (min > 60) {
minToHour = (min / 60);
min2 = (min % 60);
hour = hour + minToHour;
}
String hString;
String mString;
String string;
if (hour < 10) {
hString = "0" + String.valueOf(hour);
} else {
hString = String.valueOf(hour);
}
if (min < 10) {
mString = "0" + String.valueOf(min);
} else {
mString = String.valueOf(min);
}
if (sec < 10) {
string = "0" + String.valueOf(sec);
} else {
string = String.valueOf(sec);
}
return hString + ":" + mString + ":" + string;
}
关于两个时间(00:00:00)相加的实现方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。