As indicated in this ticket, it's a bit cumbersome (though doable) to make Spring MVC properly bind the ISO dates and times created through HTML input elements of type date
or time
. A custom WebMvcConfigurer
can be used to enable this by default:
@Bean
WebMvcConfigurer isoDatesByDefault() {
return new WebMvcConfigurer() {
public void addFormatters(FormatterRegistry registry) {
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
registrar.setUseIsoFormat(true);
registrar.registerFormatters(registry);
}
}
}
As it's very likely to be what users expect to work by default, it would be cool if this could be enabled via a property. I guess for backwards compatibility reasons it should stay deactivated by default.
Comment From: wilkinsona
Joining some dots. This was requested in https://github.com/spring-projects/spring-boot/issues/18511 alongside properties for configuring the time and date-time format. It was closed as being superseded by a pull request. The pull request doesn't add the ISO support, just the properties for time and date-time format.
There are two approaches that could be taken here:
- Add a separate property for enabling ISO formatting. This would then result in the properties for the date, time, and date-time formats being ignored.
- Allow a special value of
iso
(case-insensitive) to be used when configuring thedate
,time
, anddate-time
formats.
There are pros and cons for each of these. The pro for 1 is that it gives you a single property to enable ISO formatting. The con is that it can lead to other properties being ignored. The pro for 2 is that no properties will be ignored as a result of another property being set. The con is that you need to set three properties to enable ISO formatting.
2 is our preferred option.