计算两个时间段相加比如0:21:10+1:01:21(当个位和十位为一位数时自动补0)
public static String calc(String time1, String time2) { int temp1 = 0; int temp2 = 0; int tempa = 0; int tempb = 0; int tempq = 0; int tempp = 0; int hour = 0; int min = 0; int second = 0; String[] timeList1 = time1.split("[: ]+"); String[] timeList2 = time2.split("[: ]+"); //秒 temp1 =Integer.valueOf(timeList1[2]); temp2 =Integer.valueOf(timeList2[2]); if((temp1 +temp2)>=60) { second = temp1 + temp2 - 60; min++; } else { second = temp1 + temp2; } //分 tempa=Integer.valueOf(timeList1[1]); tempb =Integer.valueOf(timeList2[1]); if((tempa +tempb)>=60) { min = min+tempa + tempb - 60; hour++; } else { min = min + tempa + tempb; } tempq=Integer.valueOf(timeList1[0]); tempp =Integer.valueOf(timeList2[0]); hour=hour+tempp+tempq; String format=null; String time = hour + ":" + min + ":" + second; String[] split1 = time.split(":"); if(split1[2].length()<2){ split1[2]="0"+split1[2]; } if(split1[1].length()<2){ split1[1]="0"+split1[1]; } format=split1[0]+":"+split1[1]+":"+split1[2]; return format; }