LocalDate from() method in Java


An instance of a LocalDate object can be obtained from a Temporal object using the from() method in the LocalDate class in Java. This method requires a single parameter i.e. the Temporal object and it returns the LocalDate object that is obtained from the Temporal object.

A program that demonstrates this is given as follows −

Example

 Live Demo

import java.time.*;
public class Main {
   public static void main(String[] args) {
      LocalDate ld = LocalDate.from(ZonedDateTime.now());
      System.out.println("The LocalDate is: " + ld);
   }
}

Output

The LocalDate is: 2019-02-16

Now let us understand the above program.

The instance of the LocalDate object is obtained from the Temporal object using the from() method and then it is displayed. A code snippet that demonstrates this is as follows −

LocalDate ld = LocalDate.from(ZonedDateTime.now());
System.out.println("The LocalDate is: " + ld);

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

69 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements