I am looking for date functions which will allow me to subract 1 day, 1 week, 1 month, 3 mths, 1 year.
Date now = new Date(); From now, I want to subtract 1 day, 1 week, 1 month, 3 mths, 1 year.
I searched the the java.util classes. java.uil.Calendar has a add() method but it doesn't return a java.util.Date object.
Can anyone tell me how i could do this subtraction and the return value is a java.util.Date object.
Thanks, Gayatri
Dave Wingate
Ranch Hand
Joined: Mar 26, 2002
Posts: 262
posted
0
It's been a while ... but I think you want something along the lines of:
Date startingDate; GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startingDate); gc.add(Calendar.DAY_OF_YEAR, -1); Date result = gc.getTime();
Please don't edit your posts after they have been replied to. It makes the replies look odd. If Tony hadn't quoted your post I wouldn't have understood what he was going on about.