Java - Use TemporalQuery and string parse and create a specific datetime object.

Introduction

The following snippet of code uses this version of the parse() method.

The second parameter is the method reference of the from() method of the LocalDate class.

Demo

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Main {
  public static void main(String[] args) {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
    LocalDate ld = formatter.parse("01/10/2018", LocalDate::from);
    System.out.println(ld);/*w  ww.  j  a  va2  s .c o  m*/
  }
}

Result

Related Topic