• Post Reply Bookmark Topic Watch Topic
  • New Topic

Date manupulation  RSS feed

 
Gurpreet Saini
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there,
How shall I compare the Dates in Java code whereas, Date manipulation is included such as adding moth and a day in Date class object. Will it return the same in date object ?. If yes, then please write the short snippet for that. The conditions are:
1. Server side validations are to be performed. We are using only simple java classes no servlets and no JSP and no EJB.
thanks in advance,
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on what type of comparison, if you just want to know if one date is before another:

The result will be, 1 id d1 > d2, 0 if d1 == d2, and -1 if d1 < d2.
TO add or subtract dates, you should use GregorianCalendar to handle that, you can use add() or roll() methods.
 
Gurpreet Saini
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi yan,
Very thank u for your prompt response. Forget about the comparison. We just want to add month or a day in a Date object as our requirement. How this is possible ?. And after this addition we must get the return either in date object or String object.
thank you,
 
Tim West
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Adrian says, read up on the GregorianCalendar class. In particular, add() might just be handy
There are methods for converting to/from Dates too.

-Tim
[ April 19, 2004: Message edited by: Tim West ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!