Java SQL Time Create sumTimes(String[] timeStrings, DateFormat df)

Here you can find the source of sumTimes(String[] timeStrings, DateFormat df)

Description

sum Times

License

Apache License

Declaration

public static Time sumTimes(String[] timeStrings, DateFormat df) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.Time;
import java.text.DateFormat;
import java.text.ParseException;

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static Time sumTimes(String[] timeStrings, DateFormat df) {
        int secs = 0, mins = 0, hrs = 0;
        Calendar calendar = Calendar.getInstance();
        for (int i = 0; i < timeStrings.length; i++) {
            String dateString = timeStrings[i];
            Date date = new Date();
            try {
                date = (Date) df.parse(dateString);
            } catch (ParseException e) {
                e.printStackTrace();//from  w w w .  jav a  2  s.  c om
            }
            calendar.setTime(date);
            secs += calendar.get(Calendar.SECOND);
            mins += calendar.get(Calendar.MINUTE);
            hrs += calendar.get(Calendar.HOUR_OF_DAY);
        }
        calendar.set(0, 0, 0, hrs, mins, secs);
        Date d = calendar.getTime();
        return Time.valueOf(df.format(d));
    }
}

Related

  1. getWaitTimeout(Connection con)
  2. getYear(String dateTime)
  3. getYear(String dateTime)
  4. substract(Time thisDeparture, Time firstDeparture)
  5. SumTime(Time t1, Time t2)
  6. time2Double(java.sql.Time time)
  7. time2String(final java.sql.Time value)
  8. timeToBytes(Time t)
  9. timeToCalendar(Time input)