springboot 格式化返回日期

1,可以在 pojo 类每个属性添加 @JsonFrormat(pattern="yyyy-MM-dd HH:mm:ss", @timeZone="GMT+8") 注解

2,可以在配置文件中全局指定

spring.jackson.date-format=yyyy-MM-dd
spring.jackson.time-zone=GMT+8
spring.jackson.serialization.write-dates-as-timestamps=false

第一行设置格式:yyyy-MM-dd HH:mm:ss

第二行设置时区

第三行表示不返回时间戳,如果为 true 返回时间戳,如果这三行同时存在,以第三行为准即返回时间戳

猜你喜欢

转载自www.cnblogs.com/huanggy/p/9471827.html