If you are using Java 8, you can use the native Java Time library that was developed by the same guy (Stephen Colebourne) who created Joda time. It's pretty easy to parse and display dates in various formats.

Your main issue seems to be that you are treating your expected object as a LocalDateTime, but there is no time present. This is essentially throwing your code through a runtime error that states that you need to include time, so you should use a LocalDate instead.

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

public class StringToLocalDate {
    public static String DATE_FORMAT_INPUT = "ddMMyyyy";
    public static String DATE_FORMAT_OUTPUT = "yyyy-MM-dd";

    public static void main(String[] args) {
        System.out.println(formatted(convert("21022019")));
    }

    public static String formatted(LocalDate date) {
        return date.format(DateTimeFormatter.ofPattern(DATE_FORMAT_OUTPUT));
    }

    public static LocalDate convert(String dateStr) {
        return LocalDate.parse(dateStr, DateTimeFormatter.ofPattern(DATE_FORMAT_INPUT));
    }
}

If you need to use a Java version before 1.8, you can use the following. It is very similar.

import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;

public class StringToLocalDate {
    public static String DATE_FORMAT_INPUT = "ddMMyyyy";
    public static String DATE_FORMAT_OUTPUT = "yyyy-MM-dd";

    public static void main(String[] args) {
        System.out.println(formatted(convert("21022019")));
    }

    public static String formatted(LocalDate date) {
        return date.toString(DateTimeFormat.forPattern(DATE_FORMAT_OUTPUT));
    }

    public static LocalDate convert(String dateStr) {
        return LocalDate.parse(dateStr, DateTimeFormat.forPattern(DATE_FORMAT_INPUT));
    }
}
Answer from Mr. Polywhirl on Stack Overflow
🌐
Reddit
reddit.com › r/learnjava › converting string of uk date format to localdate
r/learnjava on Reddit: converting string of UK date format to LocalDate
May 16, 2022 -

I am importing from a csv file using a Scanner object and using split to get an array of strings for each row. So far, so good, so easy. I need the date in column 2 to be cast to LocalDate . I have been reading and goggling for hours but I keeping errors from LocalDate.parse I have tried using simple date formating, I have tired using DateTimeFormatter and lots of other methods I have read about. The parse keeps failing at index 0. The date is in format dd/MM/yyyy

How can I convert this to LocalDate?

****edit 1 to show code examples as people have correctly pointed out that I didnt add any (sorry)

Data sample

1,14/05/2022,James
2,21/06/2022,Iona
5,02/05/2022,Pippa

the date is coming from here

public void readFromCSV(String path) {
    try (Scanner lineIn = new Scanner(Paths.get(path))) { 
    while (lineIn.hasNextLine()) { 
        String row = lineIn.nextLine();
        String[] words = row.split(",");

I have tried the following different methods

    //Method 1 
    LocalDate date = LocalDate.parse(words[0]);

    //Method 2
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(("YYYY/MM/DD"));
LocalDate date = LocalDate.parse(words[1],formatter);

    //Method 3
     SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH)
LocalDate date = LocalDate.parse(words[1],formatter);

    //Method 4
    Date formattedDate = formattedDate.toLocalDate(words[1]);
    LocalDate date = LocalDate.parse(formattedDate);

    //Method 5
    LocalDate date = LocalDate.parse(words[1], DateTimeFormatter.ofPattern("yyyy-MM-dd").withLocale(Locale.ENGLISH));

The error I get from the catch is

error - java.time.format.DateTimeParseException: Text '14/05/2022' could not be parsed at index 0

*****Solved

    words[1] = words[1].replace("/" , "-");
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");            
LocalDate date = LocalDate.parse(words[1],formatter);

🌐
GeeksforGeeks
geeksforgeeks.org › java › convert-string-to-localdate-in-java
Convert String to LocalDate in Java - GeeksforGeeks
January 29, 2024 - In this example, I take one date value as a String value after that by using the LocalDate Parse method we convert the String into a LocalDate Value. After that, for better understanding, I display the class names of the input string as well ...
Top answer
1 of 5
6

If you are using Java 8, you can use the native Java Time library that was developed by the same guy (Stephen Colebourne) who created Joda time. It's pretty easy to parse and display dates in various formats.

Your main issue seems to be that you are treating your expected object as a LocalDateTime, but there is no time present. This is essentially throwing your code through a runtime error that states that you need to include time, so you should use a LocalDate instead.

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

public class StringToLocalDate {
    public static String DATE_FORMAT_INPUT = "ddMMyyyy";
    public static String DATE_FORMAT_OUTPUT = "yyyy-MM-dd";

    public static void main(String[] args) {
        System.out.println(formatted(convert("21022019")));
    }

    public static String formatted(LocalDate date) {
        return date.format(DateTimeFormatter.ofPattern(DATE_FORMAT_OUTPUT));
    }

    public static LocalDate convert(String dateStr) {
        return LocalDate.parse(dateStr, DateTimeFormatter.ofPattern(DATE_FORMAT_INPUT));
    }
}

If you need to use a Java version before 1.8, you can use the following. It is very similar.

import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;

public class StringToLocalDate {
    public static String DATE_FORMAT_INPUT = "ddMMyyyy";
    public static String DATE_FORMAT_OUTPUT = "yyyy-MM-dd";

    public static void main(String[] args) {
        System.out.println(formatted(convert("21022019")));
    }

    public static String formatted(LocalDate date) {
        return date.toString(DateTimeFormat.forPattern(DATE_FORMAT_OUTPUT));
    }

    public static LocalDate convert(String dateStr) {
        return LocalDate.parse(dateStr, DateTimeFormat.forPattern(DATE_FORMAT_INPUT));
    }
}
2 of 5
5

You should use another pattern to parse input date

   public static void main(String[] args) {

        System.out.println(convert("21022019"));
    }

    static LocalDate convert(String date) {
        return LocalDate.parse(date, DateTimeFormat.forPattern("ddMMyyyy"));
    }
🌐
Attacomsian
attacomsian.com › blog › java-convert-string-to-localdate
How to convert string to LocalDate in Java
October 14, 2022 - // parse custom date strings LocalDate date = LocalDate.parse("December 15, 2019", DateTimeFormatter.ofPattern("MMMM dd, yyyy")); LocalDate date2 = LocalDate.parse("07/17/2019", DateTimeFormatter.ofPattern("MM/dd/yyyy")); LocalDate date3 = LocalDate.parse("02-Aug-1989", DateTimeFormatter.ofPattern("dd-MMM-yyyy")); // print `LocalDate` instances System.out.println(date); System.out.println(date2); System.out.println(date3); The above code snippet will print the following on the console: ... Check out how to convert a string to date in Java guide for more string-to-date conversion examples.
🌐
InfluxData
influxdata.com › home › how to convert string to date in java
How to Convert String to Date in Java | InfluxData
July 25, 2024 - This example uses DateTimeFormatter to define the pattern of the date string and then parses it into a LocalDate object. Due to its immutability and thread safety, the Java 8 Date and Time API is preferred for new projects.
🌐
Czechidm
wiki.czechidm.com › home › tutorial › dev › groovy scripts tips & tricks › convert string to localdate
Convert String to LocalDate [IdStory Identity Manager]
You should specify that the original String can have a different number millisecond positions (from 0 to 6 in the given example). import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoField; import java.time.format.DateTimeFormatterBuilder; if (attributeValue == null) { return null; } DateTimeFormatter dateFormat = new DateTimeFormatterBuilder() .appendPattern("yyyy-MM-dd HH:mm:ss") .appendFraction(ChronoField.MICRO_OF_SECOND, 0, 6, true) .toFormatter(); LocalDate localDate = LocalDate.parse(attributeValue, dateFormat); return localDate;
🌐
GitHub
gist.github.com › ariesmcrae › df53f9b423246e42b2021e8eeb4312b0
Convert string to LocalDate in Java 8+ · GitHub
Convert string to LocalDate in Java 8+. GitHub Gist: instantly share code, notes, and snippets.
🌐
Coderanch
coderanch.com › t › 615504 › java › String-joda-LocalDate-fromat-dd
String to joda LocalDate fromat of dd-MMM-yy (Features new in Java 8 forum at Coderanch)
July 10, 2013 - If you want to output the LocalDate object as a string in a particular format you create a suitable DateTimeFormatter and use one of the print() methods or call the LocalDate object's toString() method passing in the pattern to use.
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › java dates › convert string to date in java
Convert String to Date in Java | Baeldung
March 26, 2025 - Converting a String with a custom date format into a Date object is a widespread operation in Java. For this purpose we’ll use the DateTimeFormatter class, which provides numerous predefined formatters, and allows us to define a formatter. Let’s start with an example of using one of the predefined formatters of DateTimeFormatter: String dateInString = "19590709"; LocalDate date = LocalDate.parse(dateInString, DateTimeFormatter.BASIC_ISO_DATE);
🌐
Substack
anshikasingh625494.substack.com › p › java-8-interview-gold-5-year-experienced
Java 8 - Interview Gold (5+ year experienced)
3 weeks ago - 30. How to convert String to LocalDate? 31. Thread safety of Java 8 Date-Time API · DEFAULT & STATIC METHODS (Interfaces) 32. Why default methods were introduced? 33. Multiple interface default method conflict – how resolved? 34. Can a default method be overridden?
🌐
Mkyong
mkyong.com › home › java8 › java 8 – how to convert string to localdate
Java 8 - How to convert String to LocalDate - Mkyong.com
February 4, 2020 - 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 · ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-convert-a-string-to-a-localdate-in-java
How to Convert a String to a LocalDate in Java? - GeeksforGeeks
July 23, 2025 - An example demonstrates how to ...fPattern("yyyy-MM-dd"); // Convert user input to LocalDate LocalDate localDate = LocalDate.parse(dateString, formatter); // Print the resulting LocalDate System.out.println("Converted LocalDate: ...
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Java 8 Convert a String to LocalDate Example - Java Code Geeks
February 25, 2019 - The given date format is communicated to the Java8 Date-Time API using the ofPattern method of the DateTimeFormatter class · ofPattern method returns the DateTimeFormatter instance having the required date format set in it · Programmers pass the original date string and the date formatter as an input argument to the LocalDate.parse() method.
🌐
Baeldung
baeldung.com › home › java › java dates › format localdate to iso 8601 with t and z
Format LocalDate to ISO 8601 With T and Z | Baeldung
January 5, 2024 - Java provides a flexible way to format date and time objects, including LocalDate using the DateTimeFormatter class. Instances of DateTimeFormatter are thread-safe, making them suitable for use in multi-threaded environments without the need for external synchronization. Here’s how we can use it to format a LocalDate to ISO 8601: class LocalDateToISO { String formatUsingDateTimeFormatter(LocalDate localDate) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX"); String formattedDate = localDate.atStartOfDay().atOffset(ZoneOffset.UTC).format(formatter); return formattedDate; }
🌐
Medium
medium.com › @AlexanderObregon › javas-localdate-parse-method-explained-d2c2bb7322cb
Java’s LocalDate.parse() Method Explained | Medium
August 31, 2024 - The LocalDate.parse() method in Java is a great tool for converting string representations of dates into LocalDate objects.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › time › LocalDate.html
LocalDate (Java Platform SE 8 )
October 20, 2025 - This method matches the signature of the functional interface TemporalQuery allowing it to be used as a query via method reference, LocalDate::from. ... Obtains an instance of LocalDate from a text string such as 2007-12-03.
🌐
SourceBae
sourcebae.com › home › how to convert string to localdate in java: a comprehensive guide
How to Convert String to LocalDate in Java: A Comprehensive Guide - SourceBae
August 21, 2025 - First, you need to parse the string that represents a date into a LocalDate object. Java provides the LocalDate.parse() method for this purpose.
🌐
W3Schools
w3schools.com › java › java_date.asp
Java Date and Time
To display the current date, import the java.time.LocalDate class, and use its now() method: import java.time.LocalDate; // import the LocalDate class public class Main { public static void main(String[] args) { LocalDate myObj = LocalDate.now(); // ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › localdate-tostring-method-in-java-with-examples
LocalDate toString() method in Java with Examples - GeeksforGeeks
December 17, 2018 - The toString() method of a LocalDate class is used to get this date as a String, such as 2019-01-01.The output will be in the ISO-8601 format uuuu-MM-dd. Syntax: public String toString() Parameters: This method does not accepts any parameters.