Java 8 – How to convert String to LocalDate

Here are a few Java examples of converting a String to the new Java 8 Date API – java.time.LocalDate DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/MM/yyyy"); String date = "16/08/2016"; //convert String to LocalDate LocalDate localDate = LocalDate.parse(date, formatter); The key is understand the DateTimeFormatter patterns Note You may interest at this classic java.util.Date example – How to …

Read more

Java regex validate date format examples

This article shows how to use regex + code to validate a date format, support single and leading zero month and day format (1 or 01), check for the 30 or 31 days of the month, and leap year validation. Below are the requirements for a valid date. Year format, 1900, 2099 regex Month format, …

Read more