Java Data Type How to - Parse String '20.01.2014' as custom format dd.MM.yyyy








Question

We would like to know how to parse String '20.01.2014' as custom format dd.MM.yyyy.

Answer

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
//from  w  w  w.  j  a  va  2 s .  com
public class Main {
  public static void main(String[] args) {

    LocalDate fromCustomPattern = LocalDate.parse("20.01.2014", DateTimeFormatter.ofPattern("dd.MM.yyyy"));
    
    System.out.println(fromCustomPattern);
  }
}

The code above generates the following result.