Java Utililty Methods SQL Date to String

List of utility methods to do SQL Date to String

Description

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

Method

Stringdate2str(java.util.Date date)
datestr
if (date == null)
    return "";
try {
    return MMddYYYY_HHmmss.format(date);
} catch (Exception e) {
    return "";
Stringdate2String(final java.sql.Date value)
Date to string
return value.toString();
StringtoString(Date date)
to String
if (date instanceof Timestamp) {
    return toString((Timestamp) date);
} else {
    return Long.toString(date.getTime());
StringtoString(Date date)
to String
if (date == null) {
    return "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
StringtoString(Date date, String dateFormat)
to String
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
return formatter.format(date);
StringtoString(Date date, String format)
to String
return toString((java.util.Date) date, format);
StringtoString(Date obj)
to String
if (obj == null) {
    return "";
DateFormat dftime = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str = dftime.format(obj);
if (str.indexOf("00:00:00") < 0) {
    return str;
} else {
...
StringtoString(java.sql.Date sqlDate, String format)
converts a java.sql.Date string with appropriate format
if (DISPLAY_DATE_FORMAT.equalsIgnoreCase(format)) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(sqlDate);
    return getDateAsString(calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DATE),
            calendar.get(Calendar.YEAR));
else if (DISPLAY_DATE_TIME_FORMAT.equals(format)) {
    Calendar calendar = Calendar.getInstance();
...
StringtoString(Object date)
Convert an Object to a String using Dates
if (date == null) {
    return null;
if (java.sql.Timestamp.class.isAssignableFrom(date.getClass())) {
    return OUT_TIMESTAMP_FORMAT.format(date);
if (java.sql.Time.class.isAssignableFrom(date.getClass())) {
    return OUT_TIME_FORMAT.format(date);
...
StringtoString(Object object)
to String
if (object == null) {
    return "";
} else if (object instanceof Date) {
    return df.format(object);
} else if (object instanceof Timestamp) {
    return df.format(object);
} else
    return object.toString();
...