Here you can find the source of getNurseCoverageEndTime(Time startTime, Time shiftLength)
public static Time getNurseCoverageEndTime(Time startTime, Time shiftLength)
//package com.java2s; //License from project: Apache License import java.sql.Time; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String TIME_24_HOUR_FORMAT = "HH:mm:ss"; public static Time getNurseCoverageEndTime(Time startTime, Time shiftLength) {/*from ww w .j a va 2s.c om*/ String[] timeArray = { formatTime(startTime, TIME_24_HOUR_FORMAT), formatTime(shiftLength, TIME_24_HOUR_FORMAT) }; Time endTime = sumTimes(timeArray, new SimpleDateFormat( TIME_24_HOUR_FORMAT)); return endTime; } public static String formatTime(Time time, String format) { SimpleDateFormat sf = new SimpleDateFormat(format); return sf.format(time); } 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(); } 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)); } }