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

application.properties

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

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

bean

@JsonFormat
	private Date modifyDate;

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

后续

若是使用了extends WebMvcConfigurationSupport方式配置,若是想要使用上面的方式配置时间格式,须要将extends WebMvcConfigurationSupport替换为implements WebMvcConfigurergithub

参考

Appendix A. Common application propertiesspring

Custom WebMvcConfiguration breaks Jackson formattingapp

相关文章
相关标签/搜索