Android Utililty Methods Calendar Format

List of utility methods to do Calendar Format

Description

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

Method

StringgetCurrentDateString(String dateFormat)
get Current Date String
Calendar cal = Calendar.getInstance(TimeZone.getDefault());
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
sdf.setTimeZone(TimeZone.getDefault());
return sdf.format(cal.getTime());
StringgetAsString(Calendar date)
get As String
return df.format(date.getTime());
StringformatCalendar(Calendar calendar)
format Calendar
return formatCalendar(calendar, DEFAULTFORMAT);
StringformatCalendar(Calendar calendar, String pattern)
format Calendar
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(calendar.getTime());
StringformatDateTime(Calendar dateTime)
format Date Time
final SimpleDateFormat sDateFormat = new SimpleDateFormat(
        "MMM d yyyy, HH:mm aaa");
return sDateFormat.format(dateTime.getTime());
StringgetLongFriendlyDate(Calendar cal)
get Long Friendly Date
return getLongFriendlyDate(cal.getTime());
StringgetSelectedDate(Calendar calendar, String pattern)
get Selected Date
if (TextUtils.isEmpty(pattern)) {
    pattern = NORMAL_PATTERN;
SimpleDateFormat formatter = new SimpleDateFormat(pattern);
Date curDate = calendar.getTime();
String str = formatter.format(curDate);
return str;
StringgetShortFriendlyDate(Calendar cal)
get Short Friendly Date
return getShortFriendlyDate(cal.getTime());