Calendar calendar = Calendar.getInstance(); //把当前时间减去3个月,如果为负数则会把年份往前推,比如2010年1月-3会变成2009年10月 calendar.add(Calendar.MONTH,-3); Timestamp time = new Timestamp(calendar.getTimeInMillis()); //获取客户上次的订单时间---orderTime CustomerOrder cusOrder = this.df.getCustomerOrderDao().get(customerId); Timestamp orderTime = cusOrder.getTime(); //判断是否过期,true就是超过3个月 if (time.after(orderTime)){ };
原文:https://www.cnblogs.com/qianxiaoPro/p/14604808.html