Skip to content

Instantly share code, notes, and snippets.

@bcalmac
Created January 13, 2020 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcalmac/8ff95f21d1629e598116b92e49f70167 to your computer and use it in GitHub Desktop.
Save bcalmac/8ff95f21d1629e598116b92e49f70167 to your computer and use it in GitHub Desktop.
Cofigure Spring type conversion to use ISO-8601 format for dates
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* Override date/time formatters with ones using ISO-8601.
*/
@Component
public class DateTimeFormatConfigurer implements WebMvcConfigurer {
@Override
public void addFormatters(FormatterRegistry registry) {
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
registrar.setUseIsoFormat(true);
registrar.registerFormatters(registry);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment