Created
January 13, 2020 01:21
-
-
Save bcalmac/8ff95f21d1629e598116b92e49f70167 to your computer and use it in GitHub Desktop.
Cofigure Spring type conversion to use ISO-8601 format for dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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