Java Utililty Methods SQL Date Convert

List of utility methods to do SQL Date Convert

Description

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

Method

Stringto_char(Date date, String format)
tchar
SimpleDateFormat formatter = new SimpleDateFormat(format);
return formatter.format(date).trim();
Stringto_char(Date date, String format)
tchar
SimpleDateFormat formatter = new SimpleDateFormat(format);
return formatter.format(date).trim();
BigDecimaltoBigDecimal(@Nullable final Date value)
to Big Decimal
return (value == null ? null : BigDecimal.valueOf(value.getTime()));
CalendartoCalender(final Date aDate)
to Calender
Calendar c = Calendar.getInstance();
c.setTimeInMillis(aDate.getTime());
return c;
java.sql.DatetodaySqlDate()
Returns the current date as java.sql.Date
return new java.sql.Date(Calendar.getInstance().getTimeInMillis());
java.sql.TimestamptoDBDate(String str)
to DB Date
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(yyyyMMddHHmmssSS);
try {
    Date date = simpleDateFormat.parse(str);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    return new java.sql.Timestamp(cal.getTimeInMillis());
} catch (ParseException e) {
    e.printStackTrace();
...
StringtoEnglishDate(String stringDate)
given format of (yyyy-mm-dd hh:mm:ss.000000000 or yyyy-mm-dd) , and return dd/mm/yyyy

String year = "";
String month = "";
String dateOfMonth = "";
stringDate = stringDate.toString().substring(0, 10);
int checkyear = -1;
if (stringDate.trim().equals("")) {
    return "''";
} else {
...
StringtoGMT(final Date ts)
to GMT
return timestampToString(ts, STANDARD_DATETIMEFORMAT, TZ_UTC);
inttoInt(java.util.Date v)
Converts the Java type used for UDF parameters of SQL DATE type ( java.sql.Date ) to internal representation (int).
return toInt(v, LOCAL_TZ);
inttoIntDate(Object object, int iDefault)
to Int Date
Date date = toDate(object, null);
if (date == null)
    return iDefault;
return longDateToInt(date.getTime());