Java Springboot日期格式化
1、全局配置
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
缺点是只能Date类生效,对LocalDate和LocalDateTime无效。
2、JsonFormat注解
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
缺点是必须在类的日期和时间字段上一个个处理。
有些事情,没经历过不知道原理,没失败过不明白奥妙,没痛苦过不了解真谛。临渊羡鱼,不如退而结网!

浙公网安备 33010602011771号