Java N天有效期设置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_28729797/article/details/80020719

今天写了一个时间定时器,可以做类似于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;
}

猜你喜欢

转载自blog.csdn.net/sinat_28729797/article/details/80020719