• Post Reply Bookmark Topic Watch Topic
  • New Topic

Substracting days in java  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello

i am trying to get todays date minus 9 days, minus 19 days and minus 29 days
How can i substract 9, 19 , 29 or any number of days from todays date in java? this is the code i have written so far, please help me i am confused and dont know what to do
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the documentation for java.util.Calendar and look for a method that has a java.util.Date as a return value.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
code
----------------------------------
public Date getTheAfterDay(Date date, int days) {
GregorianCalendar startCalendar = new GregorianCalendar();
startCalendar.setTime(date);
startCalendar.add(GregorianCalendar.DATE, days);
System.out.println(startCalendar.getTime());
return startCalendar.getTime();
}
----------------------
I think you can use like this:
getTheAfterDay(new Date(),9);
getTheAfterDay(new Date(),-19);
please try it.
[ August 03, 2006: Message edited by: James Brown ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!