File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to add Date  to 1 more day? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "How to add Date  to 1 more day?" Watch "How to add Date  to 1 more day?" New topic
Author

How to add Date to 1 more day?

chaohua wang
Ranch Hand

Joined: Dec 22, 2002
Posts: 62
Hi, Folks,

I want to add 1 more day for a Date.
I tied to to do like this :

Date completionDate =new Date(completionDate.getTime() +12);

but it doesn't work, 12 hours is not enough?
Please help, thank you very much!

Chwang
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Have a look at the Calendar class. This is the prefered way of manipulating dates in Java. You'll notice there is an add() method that allows you to add time to your date.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12911
    
    3

Originally posted by chaohua wang:
Date completionDate =new Date(completionDate.getTime() +12);

but it doesn't work, 12 hours is not enough?
Please help, thank you very much!

With that line of code you are adding 12 milliseconds to the date - not 12 hours.

Also, a day is 24 hours, not 12 hours.
[ October 03, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

Originally posted by Jesper Young:
Also, a day is 24 hours, not 12 hours.
Except in places where daylight saving time applies, sometimes it is 23 or 25 hours. Which is why you should use the Calendar object for date and time arithmetic, as Paul Sturrock said.
chaohua wang
Ranch Hand

Joined: Dec 22, 2002
Posts: 62
Thank you very much, I got it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add Date to 1 more day?
 
Similar Threads
Custom Date class and Appointment class
Short/Long day?
Date increment in java??
help creating mutator
How to calculate date in Java