File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

computing and formatting a date

 
Eric Edwards
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am teching myself Java 5.
This date thing has got me stumped. The best thing to do is to show some code, but I have been struggling with this for 2 days and none of it works.
Thae exercise in the book I am using says to take todays date and use as the invoice date. Then format this date into a SHORT date and display it. No problem.
The other part is to take the current date and add 30 days to it and display that as a SHORT date also. I am missing something along the way.
I have impoted java.util.*;
I have tried DateUtil, GregorianCalendar, etc. Can't get this to work.
Any help would be appreciated.
Eric
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you already have a calendar object set to today's date,
all you do is use calendar's method add(field, number)
where field would be Calendar.DATE and number would be 30
 
Eric Edwards
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Michael,
Thanks for the reply. I finally got it. Think I was making it too hard.
Here is what I did:
 
Eric Edwards
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,
I went back to my program and messed with the date some more.
In checking I found that the way I had done it causes two problems:
1. In using "roll" it only changes the month field. It does not change the year field if it takes you into the next year.
Using the word "add" instead of "roll" takes care of these things.
2. Using "Calendar.DATE" is very accurate compared to adding a month on.

This has been a real learning experience for me.
Thanks again,
Eric
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic