1. 程式人生 > >spring boot返回date型別給前端,顯示的是毫秒的問題

spring boot返回date型別給前端,顯示的是毫秒的問題

資料庫欄位型別為datetime  實體儲存的型別是date型別

我們把資料從資料庫中讀取返回給前端,發現date型別顯示是毫秒,怎麼格式化,下面給你兩種方法:

全域性在配置檔案中新增:

spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8

一種是在某個欄位之上新增:

@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")

在get方法上也新增:

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")