convert date object to localdate in java code example

Example 1: java 8 string to localdate

package com.mkyong.date;

import java.time.LocalDate;

public class JavaDateExample1 {

    public static void main(String[] args) {

        String date = "2016-08-16";

        //default, ISO_LOCAL_DATE
        LocalDate localDate = LocalDate.parse(date);

        System.out.println(localDate);

    }
}
Copy

Example 2: java convert java.util.Date to LocalDate

Date yourDate = new Date(); // this will be your java.util.Date instance to convert
LocalDate date = yourDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();

Tags:

Java Example