Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

Need Java Calendar help

Thread view: 
Ryan - 19 Dec 2007 21:23 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.