Java Date Between getBetweenDates(Date fromDate, Date toDate )

Here you can find the source of getBetweenDates(Date fromDate, Date toDate )

Description

get Between Dates

License

Open Source License

Declaration

public static List<Date> getBetweenDates(Date fromDate, Date toDate
    
    ) 

Method Source Code

//package com.java2s;
/**/*  ww w .  j a v a  2  s  . c o  m*/
 * 
 * ACCJava - ACC Java Development Platform
 * Copyright (c) 2014, AfirSraftGarrier, afirsraftgarrier@qq.com
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class Main {
    public static List<Date> getBetweenDates(Date fromDate, Date toDate
    // , int calendarType
    ) {
        ArrayList<Date> resultDates = new ArrayList<Date>();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(fromDate);
        Date tmpDate = calendar.getTime();
        long endTime = toDate.getTime();
        while (tmpDate.before(toDate) || tmpDate.getTime() == endTime) {
            resultDates.add(calendar.getTime());
            calendar.add(Calendar.DAY_OF_YEAR, 1);
            tmpDate = calendar.getTime();
        }
        Date[] dates = new Date[resultDates.size()];
        return resultDates;
    }
}

Related

  1. daysBetweenDates(Date beginDate, Date endDate)
  2. daysBetweenMidnight(final Date startDate, final Date endDate)
  3. getBetweenDate(Date startDate, Date endDate)
  4. getBetweenDate(String d1, String d2)
  5. getBetweenDateBuckets(Date from, Date to)
  6. getBetweenDays(String strFromDate, String strToDate)
  7. getBetweenMonths(Date date1, Date date2)
  8. getBetweenTime(Date begin, Date end, int field)
  9. getBetweenWorkDate(int amount, Date beginDate)