今天写了一个时间定时器,可以做类似于N天有效这样的功能:
public static Date getDay(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, +3);// 时间加3天
date = calendar.getTime();
return date;
}
public boolean compareTime(Date compareDate) {
boolean flag = false;
try {
Date nowTime = new Date();
Date compareTime = getDay(compareDate);
if (nowTime.before(compareTime)) {
flag = true;
}
} catch (Exception e) {
e.printStackTrace();
}
return flag;
}