tl;dr
LocalDate
.parse(
"23/01/2001" ,
DateTimeFormatter.ofPattern( "dd/MM/uuuu" )
)
.format(
DateTimeFormatter.BASIC_ISO_DATE
)
See this code run live at IdeOne.com.
20010123
Tip: Better to exchange date-time data textually using only the standard ISO 8601 formats.
java.time
You are using terrible date-time classes that were supplanted years ago by the modern java.time classes as of the adoption of JSR 310.
LocalDate
The LocalDate
class represents a date-only value without time-of-day and without time zone or offset-from-UTC.
ISO 8601
Your desired output format is known as the "Basic" variation of the standard ISO 8601 formats. I suggest considering using the expanded variation, YYYY-MM-DD, as it is more recognizable and readable.
Also, the expanded variations are used by default in the java.time classes when parsing/generating strings. So no need to specify a formatting pattern.
LocalDate ld = LocalDate.parse( "2019-01-23" ) ; // Parsed by default, no need to specify a formatting pattern.