Convert String to LocalDate in Java

String to LocalDate Java Example
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class StringToLocalDate {

    public static void main(String[] args) {
        String stringDate = "18/04/2023";
        String dateFormat = "dd/MM/yyyy";
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(dateFormat);
        LocalDate localDate = LocalDate.parse(stringDate, dateFormatter);
        System.out.println("String to LocalDate: " + localDate);
    }
}

String to LocalDate: 2023-04-18



Related: Format LocalDate in Java using DateTimeFormatter

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!