I think It is a little complicated to explain, because you are mixing between two things ofLocalizedDate
, ofLocalizedDateTime
and the FormatStyle
:
In the first case you are calling ofLocalizedDate
with the FormatStyle.FULL
so you are ignoring the time part.
In the second case you are calling ofLocalizedDateTime
also with FormatStyle.FULL
which will include all the parts of the date, which is not the case for LocalDate
or LocalDateTime
.
To be sure lets try with MEDIUM
, or SHORT
instead of FULL
:
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).format(ldt)
=> 30 déc. 2019 à 14:57:40 - without any exception
For more details check the comments here :
/**
* Full text style, with the most detail.
* For example, the format might be 'Tuesday, April 12, 1952 AD' or '3:30:42pm PST'.
*/
FULL,
/**
* Long text style, with lots of detail.
* For example, the format might be 'January 12, 1952'.
*/
LONG,
/**
* Medium text style, with some detail.
* For example, the format might be 'Jan 12, 1952'.
*/
MEDIUM,
/**
* Short text style, typically numeric.
* For example, the format might be '12.13.52' or '3:30pm'.
*/
SHORT;
To resume we can create a this table :
|
ofLocalizedTime |
ofLocalizedDate |
ofLocalizedDateTime |
LocalTime |
MEDIUM, SHORT |
|
|
LocalDate |
|
FULL, LONG, MEDIUM, SHORT |
|
LocalDateTime |
MEDIUM, SHORT |
FULL, LONG, MEDIUM, SHORT |
MEDIUM, SHORT |
ZonedDateTime |
FULL, LONG, MEDIUM, SHORT |
FULL, LONG, MEDIUM, SHORT |
FULL, LONG, MEDIUM, SHORT |
OffsetDateTime |
MEDIUM, SHORT |
FULL, LONG, MEDIUM, SHORT |
MEDIUM, SHORT |
=> FULL, LONG, MEDIUM, SHORT are FormatStyle
You can read it as LocalDateTime
can use ofLocalizedDate
with all the format styles, and no can't accept any FormatStyle
with ofLocalizedDateTime