Hi, I am trying to take a date in the format 061876 and increment it by a certain number of days, ie. 50 days. I need to retain the format so that it returns like 08??76. I would then have to take the result 08??76 and the original date (061876) to get the number of days it was incremented. Any tips that could help with this? Thanks,
Take a look at java.text.SimpleDateFormat for the parsing and formating part, at java.util.GregorianCalendar for the calculation part. You will have to convert between java.util.Date and java.util.GregorianCalendar for this, which is a bit unwieldy, but possible.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Dear Ronald, I've written a small application for you that will do what you wanted. I've not added comments, because I think that you will be able to follow the flow quite easily and that together with the API's javadocs you will be able to understand the example without any difficulties. Note that you can call the run the application with two different argument sets. Either by giving two dates:
This will computes the difference in days between the two days. If there's a difference in years, the answer will not be correct anymore. You could of course add a check in difference in years too, but that's up to you. The second parameter set should consist of a date and a number, with the character 'd' in front of it:
This will give the date, # days after the given date. Hopefully this will help you a bit further. Date calculations are a bit tedious, but with the above example and the previous posts, you should be able to write your application with one hand on your back. Good luck, Tim
Code Example - DateTest.java
[This message has been edited by Tim Blommerde (edited September 28, 2001).]