Java Data Type How to - Check if two dates are equal in Java 8


We would like to know how to check if two dates are equal in Java 8.


import java.time.LocalDate;
/* ww w.ja v a2 s . co m*/
public class Main {
  public static void main(String[] argv) {

    LocalDate date1 =;
    LocalDate date2 = LocalDate.of(date1.getYear(), date1.getMonth(),
    if (date1.equals(date2)) {
      System.out.printf("Today %s and date1 %s are same date %n", date1, date2);


The code above generates the following result.