Here you can find the source of SumTime(Time t1, Time t2)
Parameter | Description |
---|---|
t1 | a parameter |
t2 | a parameter |
public static Time SumTime(Time t1, Time t2)
//package com.java2s; //License from project: Open Source License import java.sql.Time; public class Main { /**//from w w w . j a va 2 s .c om * Suma dos tiempos pasados * * @param t1 * @param t2 * @return */ public static Time SumTime(Time t1, Time t2) { long tm = 0; //tiempo 1 String[] arr = t1.toString().split(":"); tm += Integer.parseInt(arr[2]); tm += 60 * Integer.parseInt(arr[1]); tm += 3600 * Integer.parseInt(arr[0]); //tiempo 2 arr = t2.toString().split(":"); tm += Integer.parseInt(arr[2]); tm += 60 * Integer.parseInt(arr[1]); tm += 3600 * Integer.parseInt(arr[0]); long hh = tm / 3600; tm %= 3600; long mm = tm / 60; tm %= 60; long ss = tm; return Time.valueOf(format(hh) + ":" + format(mm) + ":" + format(ss)); } private static String format(long s) { if (s < 10) { return "0" + s; } else { return "" + s; } } }