LocalDate from() method in Java

The from() method of LocalDate class in Java method obtains an instance of LocalDate from a temporal object.


public static LocalDate from(TemporalAccessor temporal)

Parameter: This method accepts a parameter temporal which specifies the temporal object to convert and not null.

Return Value: It returns the local date and not null.

Exceptions: The function throws only DateTimeException which occurs if it is unable to convert it to a LocalDate.

Below programs illustrate the from() method of LocalDate in Java:

Note: The output will change on every run.





// Program to illustrate the from() method
import java.util.*;
import java.time.*;
public class GfG {
    public static void main(String[] args)
        LocalDate dt = LocalDate.from(ZonedDateTime.now());




Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDate.html#from(java.time.temporal.TemporalAccessor)

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.