Thursday 3 January 2013

how to get a list of dates between two dates in java

Leave a Comment

List<Date> dates = new ArrayList<Date>();
long interval = 1000 * 60 * 60*24; //1 hour in millis
long endTime = lastDateOfPreviousMonth.getTime();
long curTime = firstDateOfPreviousMonth.getTime();
while (curTime <= endTime) 
{
 dates.add(new Date(curTime));
 curTime += interval;
}

0 comments:

Post a Comment