Open In App

ChronoLocalDate from() method in Java with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

The from() method of ChronoLocalDate interface in Java method obtains an instance of ChronoLocalDate from a temporal object.

Syntax:

public static ChronoLocalDate 
    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 ChronoLocalDate and not null.

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

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

Note: The output will change on every run.




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


Output:

2019-04-28

Reference: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoLocalDate.html#from-java.time.temporal.TemporalAccessor-


Last Updated : 29 Apr, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads