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

相關文章
相關標籤/搜索