全局配置
@RestController 往前端返回的时候,Date 数据会默认使用 ISO 8601 格式返回
2024-01-04T07:05:23.000+00:00
格式化返回时间
spring:
jackson:
# 格式化返回时间 yyyy-MM-dd HH:mm:ss
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
或者采用时间戳:
spring:
jackson:
# 返回时间戳
serialization:
write-dates-as-timestamps: true
个别配置
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private Date date;