Android Utililty Methods Calendar to String Convert

List of utility methods to do Calendar to String Convert

Description

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

Method

StringconvertToDateStamp(Calendar cal)
Convert given date to string
OutputFormat: yyyymmdd_hhmm
String year = String.valueOf(cal.get(Calendar.YEAR));
String month = String.valueOf(cal.get(Calendar.MONTH) + 1);
if (month.length() == 1) {
    month = "0" + month;
String day = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
if (day.length() == 1) {
    day = "0" + day;
...
StringtoSimpleDate(Calendar calendar)
Recieves a calendar instance and returns a String with simple date format ("d MMM, yyyy" = "14 Oct, 2012")
return toSimpleDate(calendar, "d MMM, yyyy");
StringtoHumanDate(Calendar cal)
Formats a calendar instance to relative timestamp.
Calendar now = GregorianCalendar.getInstance();
int years = cal.get(Calendar.YEAR) - now.get(Calendar.YEAR);
int months = cal.get(Calendar.MONTH) - now.get(Calendar.MONTH);
int days = cal.get(Calendar.DAY_OF_MONTH)
        - now.get(Calendar.DAY_OF_MONTH);
if (years == 1)
    return "next year";
else if (years > 1)
...
StringcalendarToString(Calendar date)
calendar To String
SimpleDateFormat dateformatter = new SimpleDateFormat(
        "dd/MM/yyyy HH:mm:ss");
return dateformatter.format(date.getTime());