| 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
|
|
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
|
|
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.
|
 |
 |
|
|
subject: How to add Date to 1 more day?
|
|
|