File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Adding a day to a java.util.date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Adding a day to a java.util.date" Watch "Adding a day to a java.util.date" New topic
Author

Adding a day to a java.util.date

Giselle Dazzi
Ranch Hand

Joined: Apr 20, 2003
Posts: 168
Hi all,
how do I add dates in Java ? I guess I could do it via a GregorianCalendar object, but all I have is a java.util.date. I dont know how to turn it into a GregorianCalendar.
Can anyone help me ? either by turning a java.util.date into a Calendar object or by adding / subtracting days to a java.util.date
thx in advance


Giselle Dazzi<br />SCJP 1.4
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

I recall pain working with these two classes. Brute force solution:


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Giselle Dazzi
Ranch Hand

Joined: Apr 20, 2003
Posts: 168
Thanks, but ... those methods are deprecated...
Chris De Vries
Ranch Hand

Joined: Dec 05, 2002
Posts: 65
How about something like this:

If you run that program, you should get April 13, 2003 and whatever the current time is as output. If you start with a Date object you can use the method Calendar.setTime(Date) method to set the Calendar object to the date represented by the Date object.
I hope this helps.
Chris
Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
Giselle:
create an caledar object Calendar.getInstance(), and call its setTime(date) method, then calculate it however you want. That should resolve your problem.
Giselle Dazzi
Ranch Hand

Joined: Apr 20, 2003
Posts: 168
Thanks everyone !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding a day to a java.util.date
 
Similar Threads
Date Localization
get milliseconds from java.sql.Timestamp
Question about GregorianCalendar class
subtract day from GregorianCalendar object?
Date Localization