Regarding your variable LocalDate formattedDate, you're misunderstanding the concept of formatted date.

A formatted date is a String, because you can control it's format.

When the object is a LocalDate instance, it contains value to determine a position in the time, when you just print it it has its default formatting, it you want one specific formatting you need a String representation of your date


String year = "2021", dayString = "1", monthString = "3";

LocalDate date = LocalDate.of(
        Integer.parseInt(year),
        Integer.parseInt(monthString),
        Integer.parseInt(dayString)
);

System.out.println(date); // 2021-03-01

DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MM-yyyy");
String formattedDate = date.format(dtf);
System.out.println("Formatted Date = " + formattedDate); // Formatted Date = 01-03-2021
Answer from azro on Stack Overflow
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 8 โ€บ docs โ€บ api โ€บ java โ€บ time โ€บ LocalDate.html
LocalDate (Java Platform SE 8 )
October 20, 2025 - The maximum supported LocalDate, '+999999999-12-31'. This could be used by an application as a "far future" date. ... Obtains the current date from the system clock in the default time-zone.
Top answer
1 of 2
3

Regarding your variable LocalDate formattedDate, you're misunderstanding the concept of formatted date.

A formatted date is a String, because you can control it's format.

When the object is a LocalDate instance, it contains value to determine a position in the time, when you just print it it has its default formatting, it you want one specific formatting you need a String representation of your date


String year = "2021", dayString = "1", monthString = "3";

LocalDate date = LocalDate.of(
        Integer.parseInt(year),
        Integer.parseInt(monthString),
        Integer.parseInt(dayString)
);

System.out.println(date); // 2021-03-01

DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MM-yyyy");
String formattedDate = date.format(dtf);
System.out.println("Formatted Date = " + formattedDate); // Formatted Date = 01-03-2021
2 of 2
1

You have used Y (week-based-year) instead of y (year-of-era). Learn the difference from the documentation and from answers to this question.

Simply create a LocalDate with the year, month and day and format it to a String using a DateTimeFormatter.

Demo:

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

public class Main {
    public static void main(String[] args) {
        int day = 12, month = 6, year = 2021;
        LocalDate date = LocalDate.of(year, month, day);
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MM-uuuu", Locale.ENGLISH);
        String formatted = dtf.format(date);
        System.out.println(formatted);
    }
}

Output:

2021-06-12

ONLINE DEMO

Here, you can use y instead of u but I prefer u to y.

Learn more about the modern Date-Time API from Trail: Date Time.

Note

A LocalDate is supposed to represent date units (year, month, day), and not a specific format. The default format used by LocalDate#toString is based on ISO 8601 standard. For a specific format, you need to format it into a String as shown above. It is like representing double d = 5.0 as the 5.000 which is done by formatting d into a String of this format.

public class Main {
    public static void main(String[] args) {
        double d = 5.0;
        NumberFormat formatter = new DecimalFormat("#0.000");
        String formatted = formatter.format(d);
        System.out.println(formatted);
    }
}

Output:

5.000
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ java-8-date-localdate-localdatetime-instant
Java 8 Date - LocalDate, LocalDateTime, Instant | DigitalOcean
August 3, 2022 - Default format of LocalDate=2014-04-28 28::Apr::2014 20140428 Default format of LocalDateTime=2014-04-28T16:25:49.341 28::Apr::2014 16::25::49 20140428 Default format of Instant=2014-04-28T23:25:49.342Z Default format after parsing = 2014-04-27T21:39:48
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ java date time โ€บ how to format localdate in java
How to Format LocalDate in Java - HowToDoInJava
March 3, 2024 - Learn to format a Java LocalDate instance to String using inbuilt patterns as well as custom patterns. The default format pattern is โ€˜yyyy-MM-ddโ€™.
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ javas-localdate-parse-method-explained-d2c2bb7322cb
Javaโ€™s LocalDate.parse() Method Explained | Medium
August 31, 2024 - The simplest usage of LocalDate.parse() is with a standard ISO-8601 date format (yyyy-MM-dd), which is the default format expected by this method.
๐ŸŒ
Lokalise
lokalise.com โ€บ home โ€บ java localdate localization tutorial: step by step examples
Java LocalDate localization tutorial: step by step examples
December 19, 2025 - But, our non-localized JavaLocalDateL10n app tried to parse it in the default ISO 8601 date format (YYYY-MM-DD); so obviously, no card order was placed in the system since no date was parsed that day!
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ localdate-format-method-in-java
LocalDate format() method in Java - GeeksforGeeks
November 28, 2018 - // Program to illustrate the format() method import java.util.*; import java.time.*; import java.time.format.DateTimeFormatter; public class GfG { public static void main(String[] args) { // Parses the date LocalDate dt = LocalDate.parse("2018-11-01"); System.out.println(dt); // Function call DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/YYYY"); System.out.println(formatter.format(dt)); } }
๐ŸŒ
Javatpoint
javatpoint.com โ€บ java-localdatetime
Java LocalDateTime
Class class is an immutable class that represents time with a default format of hour-minute-second. It inherits Object class and implements the Comparable interface. class declaration Let's see the declaration of java.time.LocalTime class. public final class LocalTime extends Object implements Temporal, TemporalAdjuster, Comparable<LocalTime>, Serializable Methods of Class Method Description LocalDateTime...
๐ŸŒ
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 - Explore various techniques for formatting a LocalDate to the ISO 8601 format. This format includes the 'T' separator and the 'Z' indicating UTC time.
๐ŸŒ
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 - If the String is in ISO_LOCAL_DATE format, we can parse the String directly, no need conversion. JavaDateExample1.java ยท package com.mkyong.date; import java.time.LocalDate; public class JavaDateExample1 { public static void main(String[] args) ...
๐ŸŒ
Medium
sopheamak.medium.com โ€บ how-to-accept-various-localdate-format-59b649eba851
How to accept various LocalDate Format | by sophea Mak | Medium
December 14, 2022 - How to accept various LocalDate Format As default LocalDate format is YYYY-MM-DD. How can we make it to support other formats such as DD-MM-YYYY, and YYYY/MM/DD or others? In this article, I will โ€ฆ
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ javatime โ€บ javatime_localdate_format.htm
java.time.LocalDate.format() Method Example
package com.tutorialspoint; import java.time.LocalDate; import java.time.format.DateTimeFormatter; public class LocalDateDemo { public static void main(String[] args) { LocalDate date = LocalDate.parse("2017-02-03"); System.out.println(date); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/YYYY"); System.out.println(formatter.format(date)); } }
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_date.asp
Java Date and Time
import java.time.LocalDateTime; // import the LocalDateTime class public class Main { public static void main(String[] args) { LocalDateTime myObj = LocalDateTime.now(); System.out.println(myObj); } } ... The "T" in the example above is used to separate the date from the time. You can use the DateTimeFormatter class with the ofPattern() method in the same package to format or parse date-time objects.
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java8 โ€บ java 8 โ€“ how to format localdatetime
Java 8 - How to format LocalDateTime - Mkyong.com
November 9, 2016 - package com.mkyong.time; import ...intln("Before : " + now); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String formatDateTime = now.format(formatter); System.out.println("After : " + ...
๐ŸŒ
DEV Community
dev.to โ€บ kevinblandy โ€บ formatting-json-datelocaldatetimelocaldate-in-spring-boot-odf
Formatting json Date/LocalDateTime/LocalDate in Spring Boot - DEV Community
September 21, 2022 - Spring Boot does not provide configuration properties for formatting LocalDateTime and LocalDate, but it does provide a Jackson2ObjectMapperBuilderCustomizer interface to easily customize the formatting of LocalDateTime and LocalDate.
๐ŸŒ
Noda Time
nodatime.org โ€บ 1.4.x โ€บ userguide โ€บ localdate-patterns
Noda Time | Patterns for LocalDate values
D: Long format pattern. This is the long date pattern as defined by the culture's DateTimeFormatInfo.LongDatePattern. For example, in the invariant culture this is "dddd, dd MMMM yyyy". This is the default format pattern.