I have a simple java application which needs to pick a date off in the
future some time. I'm using the roll method, to simply jump out some
number of days ahead.
Then I attempt to print out the new day with a simple date
formatter....
---------------------
Calendar cal = Calendar.getInstance();
cal.roll(Calendar.DAY_OF_YEAR, 70);
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yy");
System.out.println("New Date: "+dateFormat.format(cal.getTime()));
--------------------
Here is the output:
New Date: 02/27/07
As you can see, it thinks the new date is still in 2007 and not 2008.
However, it did pick the right day. Feb 27, 2008 is 70 days out from
today (Dec 19).
This Calendar object is a bit tricky....
Any help would be great.
Ryan
Andreas Wollschlaeger - 19 Dec 2007 21:35 GMT
Ryan schrieb:
> I have a simple java application which needs to pick a date off in the
> future some time. I'm using the roll method, to simply jump out some
[quoted text clipped - 21 lines]
> Any help would be great.
> Ryan
Well, this is exactly what the roll() method is supposed to do - the
javadocs coming with the SDk are pretty clear on that. Perhaps
Calendars' add() method is what you want :-)
Cheers
Andreas
Ryan - 19 Dec 2007 21:51 GMT
On Dec 19, 2:35 pm, Andreas Wollschlaeger <meister.pos...@arcor.de>
wrote:
> Ryan schrieb:
>
[quoted text clipped - 30 lines]
> Cheers
> Andreas
That solved the issue. For some reason, I had just missed the add()
method.
Thanks for the help.
Roedy Green - 20 Dec 2007 18:39 GMT
>As you can see, it thinks the new date is still in 2007 and not 2008.
>However, it did pick the right day. Feb 27, 2008 is 70 days out from
>today (Dec 19)
these sorts of calculation are very easy to do with BigDate. See
http://mindprod.com/products1.html#COMMON11
Look at the TestDate class for examples.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com