Java Utililty Methods SQL Time Field

List of utility methods to do SQL Time Field

  1. HOME
  2. Java
  3. S
  4. SQL Time Field

Description

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

Method

Calendar clearTime(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;
void clearTimeCommon(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.Date clearTimeFields(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.Date clearTimeFields(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());
Timestamp getDay(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);
...
String getHoraFormatada(Time hora, String formato)
get Hora Formatada
if (hora == null || formato.length() == 0) {
 return null;
SimpleDateFormat sdf = new SimpleDateFormat(formato);
return sdf.format(hora);
String getHour(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 {
...
String getHoursAndMinutes(String dateTime)
Gets hours and minutes from complete time value.
String tmp = dateTime.split(" ")[1];
return tmp.substring(0, tmp.lastIndexOf(":"));
int getSecond(Time time)
get Second
LocalTime localTime = time.toLocalTime();
return localTime.getSecond();


AltStyle によって変換されたページ (->オリジナル) /