How to check if a Product is in its last week using the Date class

I have a Product class, which has a Date variable that represents the expiration date, now I want to check if the product is in the last expiration of the week. All I could do was find out if there is a date before or after the expiration date, but I want to find out exactly how many days to check if it missed last week.

...
Date dv = new Date();
if (dv.after(vexp))
    return false;
else
    return true; }
...

How can I change this part of my code to make it work?

EDIT sry I mean "week" as 7 days, so I need to check if it is in the last 7 days from the expiration date

+3
source share
1 answer

, 7 .

static final int ONE_DAY_MILLIS = 86400 * 1000;
//....
long deltaMillis = vexp.getTime() - dv.getTime();
if (deltaMillis < 7 * ONE_DAY_MILLIS) {
  // within last 7 days
}
+4

All Articles