Java Utililty Methods SQL Time

List of utility methods to do SQL Time

Description

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

Method

CalendarmergeDateTime(Date date, Time time)
merge Date Time
Calendar cal = Calendar.getInstance();
if (date != null) {
    cal.setTime(date);
if (time != null) {
    Calendar temp = Calendar.getInstance();
    temp.setTime(time);
    cal.set(11, temp.get(11));
...
TimestampminTime()
The value of this constant is equivalent to 0000-00-00 00:00:00.000000000, January 1, 0001.
return Timestamp.valueOf(MIN_TIME);
TimeminutesToTime(int minutes)
minutes To Time
int hr = getHours(minutes);
int minute = getMinutes(minutes);
return hmsToTime(hr, minute, 0);
Timestampparse(String dateTimeString)
parse
DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString);
return new Timestamp(dateTime.toDateTime().getMillis());
TimestampparseAMPMFormat(String datetimeString)
parse AMPM Format
DateFormat dateFormat = new SimpleDateFormat(AM_PM_DATETIME_FORMAT);
final Date date = dateFormat.parse(datetimeString);
return new Timestamp(date.getTime());
CalendarparseCalendar(final TimeZone timezone, final Locale locale, final String dateformat, final String datestring)
Parse a Date string into a Calendar according to the specified Date format, for the specified TimeZone and Locale.
final SimpleDateFormat dateFormat;
final GregorianCalendar calendar;
final java.sql.Date date;
dateFormat = new SimpleDateFormat(dateformat, locale);
dateFormat.setTimeZone(timezone);
date = new java.sql.Date(dateFormat.parse(datestring).getTime());
calendar = new GregorianCalendar(timezone, locale);
calendar.setTimeInMillis(date.getTime());
...
TimestampparseDate(String datetime, String format)
Create a Date (time) from a String, returns null on failure
Example: Timestamp t = Utils.parseDate("23-06-1975 6:08 AM", "dd-MM-yyyy hh:mm a");
SimpleDateFormat sdf = new SimpleDateFormat(format);
Date d = sdf.parse(datetime, new ParsePosition(0));
return new Timestamp(d.getTime());
java.sql.TimereadTime(ByteBuffer buffer)
read Time
move(6, buffer);
int hour = read(buffer);
int minute = read(buffer);
int second = read(buffer);
Calendar cal = getLocalCalendar();
cal.set(0, 0, 0, hour, minute, second);
return new Time(cal.getTimeInMillis());
java.sql.DateremoveTimefromDate(Date inputDate)
Method removeTimefromDate.
Calendar caldate = Calendar.getInstance();
caldate.setTime(inputDate);
int day = caldate.get(Calendar.DATE);
int month = caldate.get(Calendar.MONTH);
int year = caldate.get(Calendar.YEAR);
java.sql.Date sqldate = getSQLDate(year, month, day);
return sqldate;
TimeresetDayTime(Time date)
reset Day Time
Time result = null;
result = (date != null ? new Time(resetDay(date).getTime()) : null);
return result;