Here you can find the source of getDatesStartingFromToWithInterval( long startDate, long endDate, int dayInterval)
Parameter | Description |
---|---|
startDate | a parameter |
endDate | a parameter |
dayInterval | a parameter |
public static ArrayList<Date> getDatesStartingFromToWithInterval( long startDate, long endDate, int dayInterval)
//package com.java2s; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; public class Main { /**//from w w w. java2 s. co m * Return un ArrayList of Date objects from the starting date at the end date using the interval time from a date and * the next one * * @param startDate * @param endDate * @param dayInterval * @return */ public static ArrayList<Date> getDatesStartingFromToWithInterval( long startDate, long endDate, int dayInterval) { ArrayList<Date> dates = new ArrayList<Date>(); Date date = new Date(startDate); while ((date = addDays(date, dayInterval)).getTime() <= endDate) { dates.add(date); } return dates; } /** * Add days to an existent date * @param date * @param days * @return */ public static Date addDays(Date date, int days) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.DATE, days); //minus number would decrement the days return cal.getTime(); } }