Java Utililty Methods SQL Date Create

List of utility methods to do SQL Date Create

Description

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

Method

java.util.DateasDate(java.sql.Date sqlDate)
as Date
return sqlDate != null ? new java.util.Date(sqlDate.getTime()) : null;
TimestampasDate(Object tsObj)
as Date
if (tsObj != null) {
    long tsLong = (tsObj instanceof Number) ? ((Number) tsObj).longValue()
            : Long.parseLong(tsObj.toString());
    return new Timestamp(tsLong);
return null;
java.sql.DateasSqlDate(Date date)
Converts the given Date to a java.sql.Date .
return new java.sql.Date(date.getTime());
java.sql.DateasSqlDate(Date date)
as Sql Date
return date != null ? new java.sql.Date(date.getTime()) : null;
java.sql.DateasSqlDate(String date)
Convert string as format "yyyy-MM-dd" to java.sql.Date.
try {
    java.util.Date dt = new SimpleDateFormat("yyyy-MM-dd").parse(date);
    return new java.sql.Date(dt.getTime());
} catch (ParseException e) {
    throw new IllegalArgumentException(e);
booleanbeforeNow(final Date d)
before Now
return d.before(new Date());
DatebeginOfDay(Date date)
begin Of Day
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
java.sql.DatecastToSqlDate(Object value)
cast To Sql Date
if (value == null) {
    return null;
if (value instanceof Calendar) {
    return new java.sql.Date(((Calendar) value).getTimeInMillis());
if (value instanceof java.sql.Date) {
    return (java.sql.Date) value;
...
java.sql.Dateconvert(Date date)
Given a java.util.Date, return a java.sql.Date.
if (date instanceof java.sql.Date) {
    return (java.sql.Date) date;
} else {
    return new java.sql.Date(date.getTime());
DateconvertDate(java.sql.Date date)
Converts a java.sql.Date to java.util.Date.
return new Date(date.getTime());