Here you can find the source of getBetweenDays(String start, String end)
public static List<String> getBetweenDays(String start, String end)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; public class Main { private static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); public static List<String> getBetweenDays(String start, String end) { List<String> list = new ArrayList<String>(); try {/*from ww w . j a v a 2 s . c om*/ Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); Date d1 = DATE_FORMAT.parse(start); Date d2 = DATE_FORMAT.parse(end); c1.setTime(d1); c2.setTime(d2); while (c1.compareTo(c2) != 1) { list.add(formatDate(c1.getTime())); c1.add(Calendar.DATE, 1); } } catch (ParseException e) { e.printStackTrace(); } return list; } public static Date parse(String datetime) { try { return FORMAT.parse(datetime); } catch (ParseException e) { return new Date(); } } public static String formatDate(Date date) { return DATE_FORMAT.format(date); } public static String format(Date date) { return FORMAT.format(date); } }