Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add Date to 1 more day?

 
chaohua wang
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Paul Clapham
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, I got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic