Java Date Between getBetweenDate(String d1, String d2)

Here you can find the source of getBetweenDate(String d1, String d2)

Description

get Between Date

License

Apache License

Declaration

public static GregorianCalendar[] getBetweenDate(String d1, String d2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {

    public static GregorianCalendar[] getBetweenDate(String d1, String d2) {
        Vector<GregorianCalendar> v = new Vector<GregorianCalendar>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        GregorianCalendar gc1 = new GregorianCalendar(), gc2 = new GregorianCalendar();
        try {//from   w w w.j ava  2 s.  c  om
            gc1.setTime(sdf.parse(d1));
            gc2.setTime(sdf.parse(d2));
            do {
                GregorianCalendar gc3 = (GregorianCalendar) gc1.clone();
                v.add(gc3);
                gc1.add(Calendar.DAY_OF_MONTH, 1);
            } while (!gc1.after(gc2));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return v.toArray(new GregorianCalendar[v.size()]);
    }
}

Related

  1. daysBetweenCalendars(Calendar date1, Calendar date2)
  2. daysBetweenDate(Integer startDate, Integer endDate)
  3. daysBetweenDates(Date beginDate, Date endDate)
  4. daysBetweenMidnight(final Date startDate, final Date endDate)
  5. getBetweenDate(Date startDate, Date endDate)
  6. getBetweenDateBuckets(Date from, Date to)
  7. getBetweenDates(Date fromDate, Date toDate )
  8. getBetweenDays(String strFromDate, String strToDate)
  9. getBetweenMonths(Date date1, Date date2)