Here you can find the source of getLocalDateFromString(String sDate)
public static LocalDate getLocalDateFromString(String sDate)
//package com.java2s; //License from project: Open Source License import java.time.LocalDate; import java.time.format.DateTimeFormatter; public class Main { public static LocalDate getLocalDateFromString(String sDate) { if (sDate == null || sDate.trim().isEmpty()) { return null; }//from ww w.j a v a 2 s .c o m DateTimeFormatter dateTimeFormatter; LocalDate lDate = null; try { dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); lDate = LocalDate.parse(sDate, dateTimeFormatter); } catch (Exception ex1) { try { dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); lDate = LocalDate.parse(sDate, dateTimeFormatter); } catch (Exception ex2) { try { dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); lDate = LocalDate.parse(sDate, dateTimeFormatter); } catch (Exception ex3) { try { dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); lDate = LocalDate.parse(sDate, dateTimeFormatter); } catch (Exception ex4) { try { dateTimeFormatter = DateTimeFormatter.ofPattern("ddMMyyyy"); lDate = LocalDate.parse(sDate, dateTimeFormatter); } catch (Exception ex5) { } } } } } return lDate; } }