Java Utililty Methods SQL Date From

List of utility methods to do SQL Date From

Description

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

Method

StringgetDateTime()
get Date Time
return new Timestamp(System.currentTimeMillis()).toString().substring(0, 19);
StringgetDateTime()
get Date Time
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(new Date());
DategetDateTime(final int year, final int month, final int day, final int hour, final int minute, final int second)
Creates a java.util.Date for a specified date time in the UTC time zone.
final Calendar cal = new GregorianCalendar(UTC);
cal.clear();
cal.set(year, month - 1, day, hour, minute, second);
return cal.getTime();
java.util.DategetDateTime(Object value)
Convert an Object to a DateTime, without an Exception
try {
    return toDateTime(value);
} catch (ParseException pe) {
    pe.printStackTrace();
    return null;
DatetoDate(Calendar cal)
toDate (cal): convert Calendar to Date
if (cal == null)
    return null;
return cal.getTime();
java.sql.DatetoDate(int value)
to Date
int d = value % 32;
value >>>= 5;
int m = value % 16;
int y = value >> 4;
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(y, m - 1, d);
return new java.sql.Date(cal.getTimeInMillis());
...
DatetoDate(java.sql.Date sqlDate)
to Date
return (sqlDate == null ? null : new Date(sqlDate.getTime()));
DatetoDate(java.util.Date date)
Converts a java.util.Date into an java.sql.Date.
return date == null ? null : new Date(date.getTime());
DatetoDate(Object date)
Convert the argument date string to a vanilla java.util.Date.
if (date == null)
    return null;
if (date instanceof java.sql.Timestamp) {
    java.sql.Timestamp ts = (java.sql.Timestamp) date;
    long millis = ts.getTime();
    return new Date(millis);
if (date instanceof java.sql.Date) {
...
DatetoDate(Object o)
to Date
Date result = null;
if (o instanceof Timestamp) {
    result = o != null ? new Date(((Timestamp) o).getTime()) : null;
return result;