Java LocalDate parse String like "Feb 25 2020"

Description

Java LocalDate parse String like "Feb 25 2020"

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

public class Main {

  public static void main(String[] args) {

    String input = "Feb 25 2020";
    try {// w  w  w .  j a  v a2s.  com
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d yyyy");
      LocalDate date = LocalDate.parse(input, formatter);
      System.out.printf("%s%n", date);
    } catch (DateTimeParseException exc) {
      System.out.printf("%s is not parsable!%n", input);
      throw exc;
    }
  }
}



PreviousNext

Related