Use LocalDate to create a localDate and then you can add the timepart if you need it:

    DateTimeFormatter DATEFORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    LocalDate ld = LocalDate.parse("2017-03-13", DATEFORMATTER);
    LocalDateTime ldt = LocalDateTime.of(ld, LocalDateTime.now().toLocalTime());
    System.out.println(ldt);

or LocalDateTime

ldt = LocalDateTime.of(ld, LocalDateTime.MIN.toLocalTime());

if you just need an empty timepart

EDIT:

Look at this solution with this you can build your dynamic parser:

    DateTimeFormatter DATEFORMATTER1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");

    DateTimeFormatter DATEFORMATTER = new DateTimeFormatterBuilder().append(DATEFORMATTER1)
    .parseDefaulting(ChronoField.HOUR_OF_DAY, 0)
    .parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0)
    .parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0)
    .toFormatter();

    //DateTimeFormatter DATEFORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    LocalDateTime ldt = LocalDateTime.parse("2017-03-13", DATEFORMATTER);
Answer from Jens on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › time › format › DateTimeFormatter.html
DateTimeFormatter (Java Platform SE 8 )
October 20, 2025 - LocalDate date = LocalDate.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd"); String text = date.format(formatter); LocalDate parsedDate = LocalDate.parse(text, formatter); All letters 'A' to 'Z' and 'a' to 'z' are reserved as pattern letters.
🌐
Baeldung
baeldung.com › home › java › java dates › guide to datetimeformatter
Guide to DateTimeFormatter | Baeldung
March 26, 2025 - DateTimeFormatter europeanDateFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); System.out.println(LocalDate.from(europeanDateFormatter.parse("15.08.2014")).isLeapYear());
🌐
How to do in Java
howtodoinjava.com › home › java date time › java datetimeformatter (with examples)
Java DateTimeFormatter (with Examples)
June 11, 2024 - static final DateTimeFormatter FOMATTER = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' hh:mm a"); String output = FOMATTER.format( LocalDateTime.now() ); // 07/15/2018 at 02:49 PM
🌐
Dariawan
dariawan.com › tutorials › java › java-datetimeformatter-tutorial-examples
Java DateTimeFormatter Tutorial with Examples | Dariawan
import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.OffsetDateTime; import java.time.OffsetTime; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; public class DateTimeFormatterFormatExample { static void print(String type, String result) { System.out.printf("%s: %s\n", type, result); } public static void main(String[] args) { // LocalDate DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("dd MMM yyyy"); print("LocalDate", formatter1.format(LocalDate.now())); // LocalDateTime DateTimeFormatter formatter2 = D
🌐
Java67
java67.com › 2019 › 01 › 10-examples-of-format-and-parse-dates-in-java.html
10 Examples to DateTimeFormatter in Java 8 to Parse, Format LocalDate and LocalTime | Java67
June 16, 2016 - In this example, we are creating a custom DateTimeFormatter pattern to show dates in an Indian date format, like dd-MM-yyyy (16-06-2016). This is also the British date format, popular in England and some parts of the UK. String indianDateFormat = now.format(DateTimeFormatter.ofPattern("dd-MM-yyyy")); System.out.println("formatting in Indian date format: " + indianDateFormat); Output formatting in Indian date format: 16-06-2016
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › time › format › DateTimeFormatter.html
DateTimeFormatter (Java SE 17 & JDK 17)
January 20, 2026 - LocalDate date = LocalDate.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd"); String text = date.format(formatter); LocalDate parsedDate = LocalDate.parse(text, formatter); All letters 'A' to 'Z' and 'a' to 'z' are reserved as pattern letters.
🌐
ConcretePage
concretepage.com › java › java-8 › java-datetimeformatter
Java DateTimeFormatter
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm:ss"); Find the code to print a date-time object with given formatter.
🌐
Tabnine
tabnine.com › home page › code › java › java.time.format.datetimeformatter
java.time.format.DateTimeFormatter.ofPattern java code examples | Tabnine
public static DataType<LocalDate> dateDataType() { return dataType( "DATE", DATE, DateTimeFormatter.ofPattern("'DATE '''yyyy-MM-dd''")::format, identity()); } origin: apache/flink · public String getDate() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.of("UTC")); return formatter.format(timestamp); } } origin: dropwizard/dropwizard ·
Find elsewhere
🌐
CalliCoder
callicoder.com › how-to-format-date-time-java
How to format Date and Time in Java | CalliCoder
February 18, 2022 - import java.time.LocalDate; import java.time.format.DateTimeFormatter; public class LocalDateFormatExample { public static void main(String[] args) { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); LocalDate localDate = LocalDate.of(2020, 1, 31); System.out.println(localDate.format(dateTimeFormatter)); } }
🌐
W3Schools
w3schools.com › java › java_date.asp
Java Date and Time
import java.time.LocalDateTime; // Import the LocalDateTime class import java.time.format.DateTimeFormatter; // Import the DateTimeFormatter class public class Main { public static void main(String[] args) { LocalDateTime myDateObj = LocalDateTime.now(); System.out.println("Before formatting: " + myDateObj); DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"); String formattedDate = myDateObj.format(myFormatObj); System.out.println("After formatting: " + formattedDate); } }
🌐
javaspring
javaspring.net › blog › java-datetimeformatter-patterns
Mastering Java DateTimeFormatter Patterns — javaspring.net
import java.time.LocalDate; import java.time.format.DateTimeFormatter; public class DateTimeFormatting { public static void main(String[] args) { LocalDate today = LocalDate.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); String formattedDate = today.format(formatter); System.out.println("Formatted Date: " + formattedDate); } } You can also use a DateTimeFormatter to parse a string into a LocalDate, LocalTime, or LocalDateTime object.
🌐
Medium
medium.com › @AlexanderObregon › javas-localdate-parse-method-explained-d2c2bb7322cb
Java’s LocalDate.parse() Method Explained | Medium
August 31, 2024 - Here, the date string "24/08/2024" uses slashes (/) as separators. The DateTimeFormatter pattern dd/MM/yyyy allows LocalDate.parse() to correctly parse this format.
🌐
w3resource
w3resource.com › java-exercises › datetime › java-datetime-exercise-45.php
Java - Print yyyy-MM-dd, HH:mm:ss in various format
May 19, 2025 - import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.OffsetDateTime; import java.time.ZonedDateTime; import java.time.OffsetTime; import java.time.format.DateTimeFormatter; import java.util.Date; public class Main { public static void main(String[] args) { String result; //yyyy-MM-dd LocalDate localDate = LocalDate.now(); DateTimeFormatter formatterLocalDate = DateTimeFormatter.ofPattern("yyyy-MM-dd"); result = formatterLocalDate.format(localDate); System.out.println("\nyyyy-MM-dd: " + result); // HH:mm:ss L
🌐
javaspring
javaspring.net › blog › java-date-formatting
Java Date Formatting: A Comprehensive Guide — javaspring.net
import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Locale; public class LocaleDateFormatting { public static void main(String[] args) { LocalDate currentDate = LocalDate.now(); // Format for US locale DateTimeFormatter usFormatter = DateTimeFormatter.ofPattern("MM/dd/yyyy", Locale.US); String usFormattedDate = currentDate.format(usFormatter); System.out.println("US formatted date: " + usFormattedDate); // Format for French locale DateTimeFormatter frFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy", Locale.FRANCE); String frFormattedDate = currentDate.format(frFormatter); System.out.println("French formatted date: " + frFormattedDate); } } You can also convert a string representing a date into a date object.
🌐
Coderanch
coderanch.com › t › 753051 › databases › Java-convert-yyyy-MM-dd
Java 8 convert yyyy-MM-dd to yyyy-MM-dd HH:mm:ss.SSS (JDBC and Relational Databases forum at Coderanch)
July 16, 2022 - So formatting it in the same format as the NOW() (i.e., yyyy-MM-dd HH:mm:ss.SSS) might work. Which is "2022-07-16" defaults to the else statement.
🌐
W3Schools
w3schools.com › java › tryjava.asp
W3Schools online JAVA editor
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
Spring
docs.spring.io › spring-framework › docs › current › javadoc-api › org › springframework › format › annotation › DateTimeFormat.html
DateTimeFormat (Spring Framework 7.0.6 API)
As a consequence, 'yy' characters indicate a year in the traditional style, not a "year-of-era" as in the DateTimeFormatter specification (i.e. 'yy' turns into 'uu' when going through a DateTimeFormatter with strict resolution mode). ... The set of custom patterns to use as a fallback in case parsing fails for the primary pattern(), iso(), or style() attribute. For example, if you wish to use the ISO date format for parsing and printing but allow for lenient parsing of user input for various date formats, you could configure something similar to the following. @DateTimeFormat(iso = ISO.DATE, fallbackPatterns = { "M/d/yy", "dd.MM.yyyy" })
🌐
Joda
joda.org › joda-time › apidocs › org › joda › time › format › DateTimeFormat.html
DateTimeFormat (Joda-Time 2.14.1 API)
DateTime dt = new DateTime(); DateTimeFormatter fmt = DateTimeFormat.forPattern("MMMM, yyyy"); String str = fmt.print(dt); The pattern syntax is mostly compatible with java.text.SimpleDateFormat - time zone names cannot be parsed and a few more symbols are supported.
🌐
Medium
medium.com › @medcherrou › a-comprehensive-guide-to-date-and-time-formatting-in-java-with-datetimeformatter-fefb8e48ce9f
A Comprehensive Guide to Date and Time Formatting in Java with DateTimeFormatter | by Med Cherrou | Medium
December 13, 2024 - DateTimeFormatter parser = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String dateString = "2024-12-15 14:30:45"; LocalDateTime parsedDate = LocalDateTime.parse(dateString, parser); System.out.println(parsedDate); // 2024-12-15T14:30:45