Java SQL Time Create SumTime(Time t1, Time t2)

Here you can find the source of SumTime(Time t1, Time t2)

Description

Suma dos tiempos pasados

License

Open Source License

Parameter

Parameter Description
t1 a parameter
t2 a parameter

Declaration

public static Time SumTime(Time t1, Time t2) 

Method Source Code

//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;
        }
    }
}

Related

  1. getUserToServerDateTime(TimeZone timeZone, int dateFormat, int timeFormat, String date, Locale locale)
  2. getWaitTimeout(Connection con)
  3. getYear(String dateTime)
  4. getYear(String dateTime)
  5. substract(Time thisDeparture, Time firstDeparture)
  6. sumTimes(String[] timeStrings, DateFormat df)
  7. time2Double(java.sql.Time time)
  8. time2String(final java.sql.Time value)
  9. timeToBytes(Time t)