Java Utililty Methods SQL Time From

List of utility methods to do SQL Time From

Description

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

Method

DategetDateTime(ResultSet rs, String field, Calendar cal)
get Date Time
Date date = rs.getDate(field, cal);
Date time = rs.getTime(field, cal);
if (date == null || time == null) {
    return null;
} else {
    cal.clear();
    cal.set(1900 + date.getYear(), date.getMonth(), date.getDate(), time.getHours(), time.getMinutes(),
            time.getSeconds());
...
java.util.DategetDateTime(String dateTime)
get Date Time
java.util.Date strDate = java.sql.Date.valueOf(dateTime);
return strDate;
java.sql.DategetDateTime(String s)
Gets the date and time from the YYYY-MM-DD HH:MM:SS format.
if (s.length() != 19)
    throw new IllegalArgumentException("Invalid date: " + s);
Calendar cal = Calendar.getInstance();
int year = Integer.parseInt(s.substring(0, 4));
cal.set(Calendar.YEAR, year);
int month = Integer.parseInt(s.substring(5, 7));
if (month < 1 || month > 12)
    throw new IllegalArgumentException("Invalid date: " + s);
...
DategetDatetime(String value)
Helper to create a date-time given a string of the form yyyy-mm-dd hh:mm:ss.
return value != null ? new Date(Timestamp.valueOf(value).getTime()) : null; 
StringgetDateTimeBySecond(long timeMillis)
get Date Time By Second
Timestamp timestamp = new Timestamp(timeMillis);
return timestamp.toString();
StringgetDateTimeFormat()
get Date Time Format
return DATE_TIME_FORMAT;
TimestampgetDateTimeRtnTime(Date date, String time)
get Date Time Rtn Time
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Timestamp timeStamp = null;
sdf.setLenient(false);
try {
    String dateStr = sdf.format(date);
    timeStamp = Timestamp.valueOf(dateStr + " " + time);
} catch (Exception e) {
return timeStamp;
StringgetDateTimeStr(Date date)
getDateStr get a string with format YYYY-MM-DD HH:mm:ss from a Date object
if (date != null) {
    return FORMAT_YYYY_MM_DD_HMS.format(date);
} else
    return "";
StringgetDateTimeString(java.sql.Date dd)
get Date Time String
if (dd == null) {
    return "";
String tds = dd.toString();
java.sql.Time tt = new java.sql.Time(dd.getTime());
tds += (" " + tt.toString());
return tds;
StringgetDateTimeString(String format)
get Date Time String
return toDateTimeString(new java.util.Date(), format);