parse String to LocalDate as MM/dd/yyyy format - Java java.time

Java examples for java.time:Format

Description

parse String to LocalDate as MM/dd/yyyy format

Demo Code



//package com.java2s;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

public class Main {
  private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("MM/dd/yyyy");

  public static LocalDate parse(String value) {
    try {/*from   ww  w  .  ja  va 2 s  .c  o  m*/
      return DATE_FORMATTER.parse(value, LocalDate::from);
    } catch (DateTimeParseException e) {
      return null;
    }
  }
}

Related Tutorials