I have a project in which i need to work with the date and time classes in java. This is where
i always fails. I have a calendar object that will represents dates only not hours minutes and
seconds. This date object will start from the year 1900 or rather using the date format
1900-01-01. I need to loop through time untill the current date. So far i have only managed
to parse dates in java not using the loop methods in the GregorianCalendar class that i
must use to accomplish the task in question. Do i have to use before or after methods in
the GregorianCalendar class in a while loop or both?
What i know i must do is to here after initialize a while loop that begins with the previous mentioned
startdate (1900-01-01) and then process a date object from the GregorianCalendar instantiation variable.
Sadly for me i have not gotten past this point. If any one here could point me in the correct direction
at how to loop through a GregorianCalendar object i would be very much thankful or post links to
examples that covers the issue in question.
Rob Spoor wrote:Calendar has a method called add. With this you can increment the calendar for seconds, minutes, days, etc.
Thank you for your tip i have tried that but i can't see how to use the add method correctly. I am thinking about the leap year issue
when looping through the calendar. So far i have tried the below listed code but i dont know if i am thinking in the right direction.
It is getting clearer up there by now but what about the looping part? i guess i have to loop through both the year,
month and day of month value and not just add(Calendar.YEAR, 1); and so on in a year loop ... maybe i should
do this using arrays of objects representing the year month and day ... pardon me if i make it sound more complex
than what it maybe is.