Java - from( ) Methods

Introduction

from() static factory method derives a datetime object from the specified argument.

from() method requires data conversion on the specified argument.

Using a from() method, you derive a new datetime object from the specified argument.

The following snippet of code shows how to derive a LocalDate from a LocalDateTime:

Demo

import java.time.LocalDate;
import java.time.LocalDateTime;

public class Main {
  public static void main(String[] args) {
    LocalDateTime ldt = LocalDateTime.of(2012, 5, 2, 15, 30); // 2012-05-02T15:30
    LocalDate ld = LocalDate.from(ldt); // 2012-05-02
    System.out.println(ldt);/*from  www.  j  a  v  a2  s. c o  m*/
    System.out.println(ld);
  }
}

Result