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

StringdateToDefaultDateString(Date date)
date To Default Date String
return new SimpleDateFormat("dd/MM/yyyy").format(date);
StringdateToFMDate(Date date)
date To FM Date
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int year = cal.get(Calendar.YEAR) - 1700;
int month = cal.get(Calendar.MONTH) + 1;
int day = cal.get(Calendar.DAY_OF_MONTH);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
...
StringdateToFormattedString(Date toFormat)
Converts a Date-Object to a String with the format of the DATEPATTERN
return new SimpleDateFormat(DATEPATTERN).format(toFormat);
StringdateToHHmmStr(Date date)
date To H Hmm Str
return dateToString(date, HH_MM_PATTERN);
StringdateToHMTime(Date date)
date To HM Time
if (date != null) {
    SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
    return formatter.format(date);
} else {
    return "";
StringdateToHttpDateString(Date d)
date To Http Date String
DateFormat f = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
f.setTimeZone(TimeZone.getTimeZone("GMT"));
return f.format(d);
StringdateToHuman(Date date)
Convert a date to a humanly readable date.
if (date == null) {
    return "missing";
return m_date.get().format(date);
LongDateToInteger(Date date)
Date To Integer
SimpleDateFormat f = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
String t = date.toString();
Long dateLong = null;
try {
    Date d = f.parse(t);
    dateLong = d.getTime() / 1000;
} catch (ParseException e) {
    e.printStackTrace();
...
StringdateToIso(Date d)
date To Iso
return ISO_DATE_FORMAT.format(d);
StringdateToIso8601String(Date date)
Converts a Date into an ISO-8601 formatted datetime string.
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ENGLISH);
return df.format(date);