SimpleDateFormat slf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); Date date1 = null; String d = "2023-1-1 11:11:11"; try { date1 = slf.parse(d); } catch (ParseException e) { System.out.println(e.getMessage()); } if (date.after(date1)) { System.out.println("date>date1 输入这里"); System.out.println(slf.format(date)); System.out.println(slf.format(date1)); } else if (date.before(date1)) { System.out.println("date<date1 输入这里"); System.out.println(slf.format(date)); System.out.println(slf.format(date1)); } //compareTo 方法 //是对象比较 //大于 返1 //等于 返0 //小于 返 -1 int i = date.compareTo(date1); System.out.println(i);
标签:date1,java,System,date,日期,大小,println,slf,out From: https://www.cnblogs.com/mzdxxcdh/p/17840561.html