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

StringdateToString(Date date, String formartStr)
date To String
String strDate = null;
if ((formartStr != null) && (!"".equals(formartStr))) {
    SimpleDateFormat sdf = new SimpleDateFormat(formartStr);
    strDate = sdf.format(date);
return strDate;
StringdateToString(Date date, String format)
date To String
if (date == null) {
    return null;
DateFormat dateFormat = new SimpleDateFormat(format);
dateFormat.setLenient(true);
return dateFormat.format(date);
StringdateToString(Date date, String format)
Creates a String presentation of the given date according to the given format.
DateFormat formatter;
formatter = new SimpleDateFormat(format);
return formatter.format(date);
StringdateToString(Date date, String format)
date To String
SimpleDateFormat sdf = new SimpleDateFormat(format);
try {
    return sdf.format(date);
} catch (Exception e) {
    return null;
StringdateToString(Date date, String format)
date To String
GregorianCalendar cal = new GregorianCalendar(UTC_TIME_ZONE);
cal.setTime(date);
String[] params = new String[6];
params[0] = formatInteger(cal.get(Calendar.YEAR), 4);
params[1] = formatInteger(cal.get(Calendar.MONTH) + 1, 2);
params[2] = formatInteger(cal.get(Calendar.DAY_OF_MONTH), 2);
params[3] = formatInteger(cal.get(Calendar.HOUR_OF_DAY), 2);
params[4] = formatInteger(cal.get(Calendar.MINUTE), 2);
...
StringdateToString(Date date, String format)
date To String
try {
    if (date != null)
        return new SimpleDateFormat(format).format(date);
} catch (Exception e) {
    e.printStackTrace();
    System.gc();
return null;
...
StringdateToString(Date date, String format)
date To String
if (date == null) {
    return "";
synchronized (date) {
    SimpleDateFormat df = new SimpleDateFormat(format);
    return df.format(date);
StringdateToString(Date date, String formatStr)
dateToString.
DateFormat format = new SimpleDateFormat(formatStr);
return format.format(date);
StringDateToString(Date date, String parttern)
Date To String
String dateString = null;
if (date != null) {
    try {
        dateString = getDateFormat(parttern).format(date);
    } catch (Exception e) {
return dateString;
...
StringDateToString(Date date, String pattern)
Date To String
String strDateTime = null;
SimpleDateFormat formater = new SimpleDateFormat(pattern);
strDateTime = date == null ? null : formater.format(date);
return strDateTime;