当前位置: 动力学知识库 > 问答 > 编程问答 >

java - how to check if a Product is in his last expiration week using Date class

问题描述:

i got a class "Product" which has a Date variable that represents the expiration date, now i want to check if the product is in the last expiration week.

All i could do is manage to see if the date is before or after the expiration date but i want to know precisely how many days, to check if it falls in the last week

...

Date dv = new Date();

if (dv.after(vexp))

return false;

else

return true; }

...

how can i change this portion of my code to get it working?

EDIT sry i meant "week" as 7 days so i need to check if it is in the last 7 days of expiration date

网友答案:

This code determines whether expiration is within the last 7 days.

static final int ONE_DAY_MILLIS = 86400 * 1000;
//....
long deltaMillis = vexp.getTime() - dv.getTime();
if (deltaMillis < 7 * ONE_DAY_MILLIS) {
  // within last 7 days
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: