date manipulation

Hi. I'm currently working on a video rental system, so it needs a dynamic date manipulation to work. right now I need to subtract date1 from date2, where

date 2 = current date

and

date1 = recorded date.

i know there's a lot of other topics here that covers date maths, but they use a static type of date. what i need is

Not this:

Calendar dateOfBirth = new GregorianCalendar(1972, Calendar.JANUARY, 27);

but something that uses the current date.

[500 byte] By [hunter71485a] at [2007-11-27 1:58:24]
# 1

For date arithmetics, I'd never use Date, I'd use Calendar and/or GregorianCalendar. There are numerous topics on how to. For finding the difference in days between two Calendar objects, keep on adding one day to the first day until it's no longer before the second day, and count how many times you did that.

OleVVa at 2007-7-12 1:35:04 > top of Java-index,Java Essentials,Java Programming...
# 2
could you give me a sample?
hunter71485a at 2007-7-12 1:35:04 > top of Java-index,Java Essentials,Java Programming...
# 3

Let's see what I have. The following snippet was written for a different thread, but I hope you can make sense of it.

// The following works across change to DST

GregorianCalendar test = new GregorianCalendar(2006, Calendar.MARCH, 1);

GregorianCalendar end = new GregorianCalendar(2006, Calendar.MARCH, 31);

int countDays = 0;

while (test.before(end))

{ test.add(Calendar.DAY_OF_MONTH, 1);

countDays++;

}

System.out.println("" + countDays + " days; " + test.getTime());

It prints 30 days; Fri Mar 31 00:00:00 CEST 2006 on my computer.

OleVVa at 2007-7-12 1:35:04 > top of Java-index,Java Essentials,Java Programming...