public class Main1 { public static void main(String args[]) { String beginTime = "2020-04-01"; String endTime = "2018-07-29 12:26:32"; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { Date date1 = format.parse(beginTime); Date date = new Date(); Date date2 = format.parse(format.format(date)); System.out.println(date1.before(date2)); //Date date3 = format.parse(endTime); boolean before = date1.before(date2); System.out.println(before); System.out.println("==============="); int compareTo = date1.compareTo(date2); System.out.println(compareTo); System.out.println("================"); long beginMillisecond = date1.getTime(); long endMillisecond = date2.getTime(); System.out.println(beginMillisecond > endMillisecond); } catch (ParseException e) { e.printStackTrace(); } } }
java时间大小比较
最新推荐文章于 2022-08-17 16:06:54 发布