Android Utililty Methods Calendar to Date Convert

List of utility methods to do Calendar to Date Convert

Description

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

Method

DateCalendar2Date(Calendar c)
Calendar Date
return c.getTime();
StringgetDate(Context context, Calendar calendar)
get Date
Calendar now = Calendar.getInstance();
long diff = now.getTimeInMillis() / 1000
        - calendar.getTimeInMillis() / 1000;
diff = diff < 0 ? 0 : diff;
long years = diff / YEAR;
long months = diff / MONTH;
long weeks = diff / WEEKS;
long days = diff / DAYS;
...
HashMapgetDate(Calendar calendar)
get Date
final HashMap<String, Object> date = new HashMap<String, Object>();
date.put(YEAR, calendar.get(Calendar.YEAR));
date.put(MONTH, calendar.get(Calendar.MONTH) + 1);
date.put(DAY, calendar.get(Calendar.DAY_OF_MONTH));
date.put(HOUR, calendar.get(Calendar.HOUR_OF_DAY));
date.put(MIN, calendar.get(Calendar.MINUTE));
return date;