tl;dr
OffsetDateTime
.parse( "2023-04-20T00:00:00+02:00" )
.toLocalDate()
.toString()
See this code run at Ideone.com.
2023-04-20
String manipulation
Obviously you could simply manipulate the input string. Truncate after the first ten letters.
String result = "2023-04-20T00:00:00+02:00".substring( 0 , 10 ) ;
Or, split the string into pieces. Grab the first piece.
String result = "2023-04-20T00:00:00+02:00".split( "T" )[ 0 ] ;
java.time
You could parse the input as a date-time value.
Use only the java.time classes for date-time work. Never use the terribly flawed legacy classes such as Date
, Calendar
, and SimpleDateFormat
.
To parse your particular input, use the java.time.OffsetDateTime
class. Your input consists of three parts: a date, a time-of-day, and an offset from UTC of a number of hours and minutes. To OffsetDateTime
class fully represents all three parts.
OffsetDateTime odt = OffsetDateTime.parse( "2023-04-20T00:00:00+02:00" ) ;
In contrast, note that the LocalDateTime
class seen in the other Answer cannot represent all three parts. That class represents only the first two of the three parts. So the use of that class there is misleading and confusing.
After parsing, we can extract just the date portion, without the time of day, and without the offset.
LocalDate ld = odt.toLocalDate() ;
Generate text to represent that date value, in standard ISO 8601 format.
String result = ld.toString() ;