Java Data Type How to - Convert java.sql.Date to LocalDate








Question

We would like to know how to convert java.sql.Date to LocalDate.

Answer

import java.sql.Date;
import java.time.LocalDate;
/*from ww  w. j a v  a2s .c  o  m*/
public class Main {

  public static void main(String[] args) {
    System.out.println(convertToEntityAttribute(Date.valueOf("2000-01-12")));
  }

  public static LocalDate convertToEntityAttribute(Date date) {
    return date.toLocalDate();
  }

}

The code above generates the following result.