业务场景
判断套餐的到期时间是否大于当前时间一年或一年以上
代码
jdk1.7方法
@org.junit.Test
public void test() throws ParseException {
//获取当前时间
String nowtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
String currentDate ="2023-03-02 16:54:01";//假设当前时间
//测试到期时间
// String endDate ="2022-02-02 16:54:02"; // false
// String endDate ="2022-04-02 16:54:02"; // false
String endDate ="2024-03-03 16:54:00"; // true
// String endDate ="2023-06-02 16:54:02"; // false
// String endDate ="2024-02-02 16:54:02"; // false
// String endDate ="2024-06-02 16:54:02"; // ture
boolean bol = DateCompare(currentDate,endDate);// true:大于一年或一年以上