spring boot中jackson时间格式和东八区的设置

application.properties

# JACKSON (JacksonProperties)
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8

第一个设置就是使用24小时的时间格式;第二个设置就是设置时区为东八区。

bean

	@JsonFormat
	private Date modifyDate;

然后,在你想要格式化的属性上面使用@JsonFormat注解。

后续

如果使用了extends WebMvcConfigurationSupport方式配置,如果想要使用上面的方式配置时间格式,需要将extends WebMvcConfigurationSupport替换为implements WebMvcConfigurer

参考

Appendix A. Common application properties

Custom WebMvcConfiguration breaks Jackson formatting

转载于:https://my.oschina.net/fxtxz2/blog/1861776