Java Utililty Methods SQL Time Field

List of utility methods to do SQL Time Field

Description

The list of methods to do SQL Time Field are organized into topic(s).

Method

CalendarclearTime(final Calendar self)
Clears the time portion of this Calendar instance; useful utility where it makes sense to compare month/day/year only portions of a Calendar.
clearTimeCommon(self);
return self;
voidclearTimeCommon(final Calendar self)
Common code for #clearTime(java.util.Calendar) and #clearTime(java.util.Date) and #clearTime(java.sql.Date)
self.set(Calendar.HOUR_OF_DAY, 0);
self.clear(Calendar.MINUTE);
self.clear(Calendar.SECOND);
self.clear(Calendar.MILLISECOND);
java.sql.DateclearTimeFields(java.sql.Date date)
Convert the given java.sql.date into a java.sql.date of which all the time fields are set to 0.
Calendar timelessCal = new GregorianCalendar();
timelessCal.setTime(date);
timelessCal.set(Calendar.HOUR_OF_DAY, 0);
timelessCal.set(Calendar.MINUTE, 0);
timelessCal.set(Calendar.SECOND, 0);
timelessCal.set(Calendar.MILLISECOND, 0);
return new java.sql.Date(timelessCal.getTimeInMillis());
java.util.DateclearTimeFields(java.util.Date date)
Convert the given java.util.date into a java.util.date of which all the time fields are set to 0.
Calendar timelessCal = new GregorianCalendar();
timelessCal.setTime(date);
timelessCal.set(Calendar.HOUR_OF_DAY, 0);
timelessCal.set(Calendar.MINUTE, 0);
timelessCal.set(Calendar.SECOND, 0);
timelessCal.set(Calendar.MILLISECOND, 0);
return new java.util.Date(timelessCal.getTimeInMillis());
TimestampgetDay(long time)
Get earliest time of a day (truncate)
if (time == 0)
    time = System.currentTimeMillis();
GregorianCalendar cal = new GregorianCalendar();
cal.setTimeInMillis(time);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
...
StringgetHoraFormatada(Time hora, String formato)
get Hora Formatada
if (hora == null || formato.length() == 0) {
    return null;
SimpleDateFormat sdf = new SimpleDateFormat(formato);
return sdf.format(hora);
StringgetHour(String time)
get Hour
int hour = Integer.parseInt(time.substring(0, 2));
String ret_hour = null;
if (hour > 12) {
    if (hour < 10)
        ret_hour = "0" + Integer.toString(hour - 12);
    else
        ret_hour = Integer.toString(hour - 12);
} else {
...
StringgetHoursAndMinutes(String dateTime)
Gets hours and minutes from complete time value.
String tmp = dateTime.split(" ")[1];
return tmp.substring(0, tmp.lastIndexOf(":"));
intgetSecond(Time time)
get Second
LocalTime localTime = time.toLocalTime();
return localTime.getSecond();