Java Utililty Methods Date to String

List of utility methods to do Date to String

Description

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

Method

Stringconvert(Date date)
convert
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
return dateFormat.format(date);
Stringconvert(Date date, String style)
convert
if (date == null || style == null)
    return null;
return new SimpleDateFormat(style).format(date);
StringconvertDate(Date d)
convert Date
return df.format(d);
StringconvertDate(Date date)
convert Date
if (date != null)
    return new SimpleDateFormat("yyyy-MM-dd'T'h:m:ssZ").format(date);
else
    return null;
StringconvertDate(Date date)
Convert data to string with pattern (dd/MM).
DateFormat format = new SimpleDateFormat("dd/MM");
return format.format(date);
StringconvertDate(Date date)
convert Date
String result = "";
try {
    result = getDateFormatter().format(date);
} catch (Exception e) {
return result;
StringconvertDate(Date passedDate)
Converts a date to a standard system-wide format
final SimpleDateFormat DATE_FORMAT_DATE_ONLY = new SimpleDateFormat("dd/MM/yyyy");
return DATE_FORMAT_DATE_ONLY.format(passedDate);
StringconvertDate(final Date date)

Convierte un java.util.Date a DateFormat.SHORT.

DateFormat formatoFecha = DateFormat.getDateInstance(DateFormat.SHORT);
String fecha = formatoFecha.format(date);
return fecha.replace("/", "-");
StringconvertDate2Str(java.util.Date date, String format, String defaultValue)
convert Date Str
SimpleDateFormat sdf = new SimpleDateFormat(format);
try {
    defaultValue = sdf.format(date);
} catch (Exception e) {
return defaultValue;
StringconvertDate2String(Date date)
Turn a date into a string that can be saved and later parsed by convertString2Date().
return dateFormat.format(date);