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


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.


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 .  j  a  va2s .  c  om


Related Topic