我需要检查密码是否过期。如果他在过去 30 天内没有修改密码,我需要让他重置密码。这是我的代码。
Date lastPasswordModifiedDate =new SimpleDateFormat("MM/dd/yyyy").parse("10/30/2013");
if (lastPasswordModifiedDate == null)
{
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(0);
lastPasswordModifiedDate = cal.getTime();
}
Calendar lastPasswordChangeCal = GregorianCalendar.getInstance();
lastPasswordChangeCal.setTime(lastPasswordModifiedDate);
Date today = new Date();
lastPasswordChangeCal.add(Calendar.DAY_OF_MONTH, -30); //max 30 dates to expire
Date expireDate = lastPasswordChangeCal.getTime();
System.out.println(expireDate); //last password changed date
System.out.println(today); //today date - I changed in my system
System.out.println(today.after(expireDate));
当我打印这个
System.out.println(expireDate);
System.out.println(today);
System.out.println(today.after(expireDate));
Mon Sep 30 00:00:00 IST 2013
Tue Oct 30 22:07:44 IST 2012
false
我期待如果 lastPasswordModifiedDate >30 天或 null 它应该返回 true。