Java Day Between getBetweenDays(String start, String end)

Here you can find the source of getBetweenDays(String start, String end)

Description

get Between Days

License

Open Source License

Declaration

public static List<String> getBetweenDays(String start, String end) 

Method Source Code


//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);
    }
}

Related

  1. daysDiff(final Date data1, final Date data2)
  2. differentDaysByMillisecond(Date date1, Date date2)
  3. diffInDays(Date date1, Date date2)
  4. getBeteenDays(String begin, String end, String format)
  5. getBetweenDays(long longValue1, long longValue2)
  6. getBetweenTwoDayCalender(String startDay, String endDay)
  7. getDateDiff(Date date, int day)
  8. getDateDiff(final Date startDate, final Date endDate)
  9. getDateDifference(Date date1, Date date2)