A method that compares the dates of the Date class, which compares the date of the caller of the method with the date of the argument.
Compares the argument with the caller and returns the value as follows:
0 if the value of the method caller is equal to the argument -1 if the method caller value is before the argument 1 if the method caller value is after the argument
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Date date1,date2;
date1 = sdf.parse("20210117");
date2 = sdf.parse("20210118");
System.out.println(date1.compareTo(date2)); // -1 ->date1 is before date2
System.out.println(date2.compareTo(date1)); // 1 ->date2 is after date1
Recommended Posts