Convert Date LocalDate Java

Convert Date LocalDate Java

In this sample program we will convert java Date object to LocalDate. LocaDate been introduced in Java 8 and it has many useful functionality you could look here

  • ConvertDateToLocalDate.java:
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

public class ConvertDateToLocalDate {

	public static void main(String[] args) {
		
		Date date = new Date();
		LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
		
		System.out.println("Local date: "+localDate);
		
		System.out.println("Local date in String: "+localDate.toString());		
		

	}

}
  • Output:

Convert Date LocalDate Java

Leave a Reply

Your email address will not be published. Required fields are marked *