Just set parsedDate equal to your formatted text string, like so:
parsedDate = text;
A LocalDate object can only ever be printed in ISO8601 format (yyyy-MM-dd). In order to print the object in some other format, you need to format it and save the LocalDate as a string like you've demonstrated in your own example
DateTimeFormatter formatter = DateTimeFormatter
.ofPattern("d/MM/uuuu")
.localizedBy(myLocale); // In Java 15+, this localizes the digits; you can comment it
String text = myDate.format(formatter);
Answer from Rebecca Close on Stack OverflowJust set parsedDate equal to your formatted text string, like so:
parsedDate = text;
A LocalDate object can only ever be printed in ISO8601 format (yyyy-MM-dd). In order to print the object in some other format, you need to format it and save the LocalDate as a string like you've demonstrated in your own example
DateTimeFormatter formatter = DateTimeFormatter
.ofPattern("d/MM/uuuu")
.localizedBy(myLocale); // In Java 15+, this localizes the digits; you can comment it
String text = myDate.format(formatter);
Just format the date while printing it out:
var date = LocalDate.now();
var locale = Locale.forLanguageTag("fa");
var formatter = DateTimeFormatter
.ofPattern("d/MM/uuuu")
.localizedBy(locale); // In Java 15+, this localizes the digits; you can comment it
var dateText = date.format(formatter);
var parsedDate = LocalDate.parse(dateText, formatter);
System.out.println("date: " + date);
System.out.println("Text format " + dateText);
System.out.println("parsedDate: " + parsedDate.format(formatter));
Big D means day-of-year. You have to use small d.
So in your case use "yyyyMMdd".
You can check all patterns here.
This particular pattern is built into Java 8 and later: DateTimeFormatter.BASIC_ISO_DATE
I think you have two problems.
First, you are enclosing a String in character literals ('' vs "").
Second, the DD (day of year) in your format string needs to be dd (day of month).
DateTimeFormatter.ofPattern("yyyyMMdd");
SimpleDateFormat will not work if he/she is starting with LocalDate, which is new in Java 8. From what I can see, you will have to use DateTimeFormatter.
LocalDate localDate = LocalDate.now(); // For reference
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd LLLL yyyy");
String formattedString = localDate.format(formatter);
That should print 05 May 1988. To get the period (AKA full stop) after the day and before the month, you might have to use "dd'.LLLL yyyy".
It could be short as:
LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));