Thursday, 25 July 2013

SimpleDateFormat - How get specific date format from calendar

//25-07-2013
//Thursday, 25 July
public List<HashMap<String, String>> getCalendarsFormats() {
    Calendar calendar = Calendar.getInstance();
    List<HashMap<String, String>> dates = new ArrayList<HashMap<String, String>>();

    for (int i = 0; i < 4; i++) {
        Calendar tempCalendar = (Calendar) calendar.clone();
        tempCalendar.add(Calendar.DAY_OF_WEEK_IN_MONTH, i);

        HashMap<String, String> tempHash = new HashMap<String, String>();

        SimpleDateFormat formatter1 = new SimpleDateFormat("dd-MM-yyyy");
        String format1 = formatter1.format(tempCalendar.getTime());
        tempHash.put("format1", format1);
        SimpleDateFormat formatter2 = new SimpleDateFormat("EEEE, dd MMMM");
        String format2 = formatter2.format(tempCalendar.getTime());
        tempHash.put("format2", format2);

        dates.add(tempHash);
    }

    return dates;
}