Android Utililty Methods Date Format

List of utility methods to do Date Format

Description

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

Method

StringformatDate(Date date)
format Date
return DATE_FORMAT.format(date);
Stringnow(String dateFormat)
Returns the current date in a given format.
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
long now = System.currentTimeMillis();
return sdf.format(new Date(now));
Stringnow(String dateFormat)
now
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
return sdf.format(cal.getTime());
StringgetLongFriendlyDate(Date dt)
get Long Friendly Date
String dtStr = DateFormat.format("MMM d, yyyy", dt).toString();
Date today = getToday();
String todayStr = DateFormat.format("MMM d, yyyy", today)
        .toString();
if (dtStr.equals(todayStr)) {
    return "Today " + DateFormat.format("h:mm aa", dt);
Date yesterday = getYesterday();
...
StringgetMainClockString(Date utcDate)
get Main Clock String
if (utcDate.getTime() == 0) {
    return "";
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.CHINA);
return sdf.format(utcDate.getTime());
StringcurrentDateToString(String format)
current Date To String
SimpleDateFormat formatter = new SimpleDateFormat(format);
Date currentDate = new Date(System.currentTimeMillis());
return formatter.format(currentDate);
StringdateToString(Date paramDate, String paramString)
date To String
SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(
        paramString, Locale.FRANCE);
localSimpleDateFormat.setTimeZone(TimeZone
        .getTimeZone("Europe/Paris"));
return localSimpleDateFormat.format(paramDate);
StringchangeDateToFormatString(Date fecha, String pattern)
change Date To Format String
DateFormat formato = new SimpleDateFormat(pattern);
return formato.format(fecha);
StringcreateName(String format, long dateTaken)
create Name
Date date = new Date(dateTaken);
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.format(date);
StringformatDate(Date d)
Formats the input date to string.
return d != null ? DateFormat.getDateInstance().format(d) : "";