from() Methods

Description

from() is a static factory method which is used to derive a datetime object from the specified argument.

Unlike of(), from() requires data conversion on the specified argument.

Example

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


import java.time.LocalDate;
import java.time.LocalDateTime;
//w  w  w  .  j a v  a 2  s.com
public class Main {
  public static void main(String[] args) {
    LocalDateTime  localDateTime = LocalDateTime.of(2015, 6,  21,  13, 40);
    System.out.println(localDateTime);
    
    LocalDate localDate  = LocalDate.from(localDateTime);
    System.out.println(localDate);
  }
}

The code above generates the following result.





















Home »
  Java Date Time »
    Tutorial »




Java Date Time Tutorial