Document options for handling Date/Time parsing and formatting issues with JDK 20+ #33151
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: documentation
A documentation task
Milestone
Overview
JDK 20 adopted Unicode CLDR-14032 (Common Locale Data Repository) which changed the space character that precedes the
period
(AM or PM) in formatted date/time text from a standard space (" "
) to a narrow non-breaking space (NNBSP:"\u202F"
). Consequently, applications that rely on date/time parsing and formatting may encounter incompatible changes in behavior when using Spring on Java 20 or higher -- for example, web applications that make use of@DateTimeFormat
.On JDK 20, 21, and 22, applications can use the
-Djava.locale.providers=COMPAT
command-line argument forjava
in order to force the use of legacy locale data which uses a standard space for the space character that precedes theperiod
in formatted date/time text.Support for the aforementioned
COMPAT
mode has been removed in JDK 23; however, the Java team has introduced support for lenient parsing of space characters in JDK 23. This applies toSimpleDateFormat
as well asDateTimeFormatter
.SimpleDateFormat
andDateTimeFormatter
ConfigurationSimpleDateFormat
is lenient by default; however,DateTimeFormatter
instances are not lenient by default, and factory methods likeDateTimeFormatter.ofLocalizedTime(...)
do not create lenient formatters.To create a lenient
DateTimeFormatter
, one must forgo the use of the static factory methods inDateTimeFormatter
and instead make use of theDateTimeFormatterBuilder
. The following example shows how to create a static factory method for a lenientDateTimeFormatter
that is comparable to whatDateTimeFormatter.ofLocalizedDateTime(FormatStyle, FormatStyle)
produces.Proposal
In Spring Framework, we do not plan to introduce additional support for lenient parsing of dates using AM/PM in conjunction with
@DateTimeFormat
. We also do not plan to introduce additional support to control the format used when rendering/printing String representations of dates or times.Rather, we will document the options that Spring provides to assist developers who encounter date/time parsing and formatting issues, and we will refer developers to the updated documentation in JEP 252 provided by the JDK team.
For example,
@DateTimeFormat
already provides support for fallback patterns that allow for lenient parsing of date/time inputs.Related Resources
Related Issues
@DateTimeFormat
#30649The text was updated successfully, but these errors were encountered: