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);//from w  ww .jav  a2 s.  co m
  }
}

Result

Related Topic