Android Utililty Methods Date to String Convert

List of utility methods to do Date to String Convert

Description

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

Method

StringconvertToDateStamp(Date date)
Convert given date to string
OutputFormat: yyyymmdd_hhmm
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return convertToDateStamp(cal);
StringdateTimeToString(Date date)
date Time To String
if (date != null) {
    return (formatter.format(date));
} else
    return "";
StringdateToIsoDateString(@NotNull Date date)
Converts a Date object to an ISO-formatted String representation of it.
return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(date);
StringdateToIsoDateString(@Nullable Date date, @NotNull DateFallback fallback)
Converts a java.util.Date object to an ISO-formatted String representation of it.
if (date != null) {
    return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(date);
} else if (fallback == DateFallback.EARLIEST) {
    return getEarliestDateString();
throw new IllegalArgumentException(
        "date is null and fallback parameter is invalid!");
StringformatDate(Date date, String format)
Formats date to the string with specific time date format.
return new SimpleDateFormat(format).format(date);
StringformatDate(String format, Date date)
format Date
return new SimpleDateFormat(format, ConfigurationManager
        .getInstance().getCurrentLocale()).format(date);
StringformatDate(final Date date)
format Date
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
return sdf.format(date);
StringgetCurrentDateStr()
get Current Date Str
SimpleDateFormat dateFormat = new SimpleDateFormat(ONLY_DATE_FORMAT);
Date d = new Date(System.currentTimeMillis());
return dateFormat.format(d);
StringgetCurrentDateStrs()
get Current Date Strs
SimpleDateFormat dateFormat = new SimpleDateFormat(
        ONLY_DATE_FORMAT_s);
Date d = new Date(System.currentTimeMillis());
return dateFormat.format(d);
StringgetCurrentTimeStr()
get Current Time Str
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
Date d = new Date(System.currentTimeMillis());
return dateFormat.format(d);