springboot 格式化日期

返回日期格式化

1,每个实体属性添加 @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") 注解

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

1, 每个实体属性添加 
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone="GMT+8")
2, 配置文件全局配置 
    spring.jackson.date-format=yyyy-MM-dd
    spring.jackson.time-zone=GMT+8

接受参数日期格式化

1, 每个实体属性添加 
  @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") 2, 配置文件全局配置
  spring.mvc.date-format=yyyy-MM-dd HH:mm:ss
原文地址:https://www.cnblogs.com/huanggy/p/9471827.html