I am looking for a java library that when given from and to date would return a list of dates in weeks,months,quarter or year which ever is most applicable. I have done this manually and i wanted to know if this is already implemented and tested as a part of a standard package.
Example
Given 1/1/2009 , 1/4/2009 it should give 1/1/2009,1/2/2009,1/3/2009,1/4/2009
Given 1/1/2009 , 1/14/2009 it should give 1/1/2009,1/7/2009,1/14/2009
hope you that is clear :)
The DateTime class provided by Joda Time has methods such as plusDays(int)
, plusWeeks(int)
, plusMonths(int)
which should help.
Assuming you want to get all the dates between start
and end
in weeks (pseudocode):
DateTime start = // whatever
DateTime end = // whatever
List<DateTime> datesBetween = new ArrayList<DateTime>();
while (start <= end) {
datesBetween.add(start);
DateTime dateBetween = start.plusWeeks(1);
start = dateBetween;
}
Alternative to Jado is use standart java API
Calendar start = // whatever
Calendar end = // whatever
List<Calendar> datesBetween = new ArrayList<Calendar>();
while (start.compareTo(end) <= 0) {
datesBetween.add(start);
Calendar dateBetween = start.add(Calendar.DAY_OF_MONTH, 7);
start = dateBetween;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With