What is the best practice to iterate through a start and end date?
Asked
Active
Viewed 2,403 times
2
-
3Best 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 Answers
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