2

What is the best practice to iterate through a start and end date?

Sri
  • 5,805
  • 10
  • 50
  • 68
  • 3
    Best practice is to come up with a solution that works and is readable. And to stop wittering on about "best practice". – Stephen C Jun 24 '10 at 11:38
  • Jon Skeet´s answer to this http://stackoverflow.com/questions/1174899/java-joda-time-implement-a-date-range-iterator question may be an appropriate solution. – Jochen Walter Jun 24 '10 at 11:55

3 Answers3

2

I once used a variant of the following Date Iterator.

Not sure if it is a best practice or not, but it was a clear solution and I liked it.

0

Iterator myVeryOwnIterator = HashMap.keySet().iterator(); while(myVeryOwnIterator.hasNext()) { System.out.println(myVeryOwnIterator.next()); }

salyutan
  • 203
  • 1
  • 3
  • 10
0

If you want to iterate between certain time units such as every hour between two dates, you could take a look at this obligatory joda-time answer: Java date iterator factory, with rules specifying how to calculate the intervals

Community
  • 1
  • 1
Esko
  • 29,022
  • 11
  • 55
  • 82