SpringBoot返回date日期格式化,解决返回为TIMESTAMP时间戳格式或8小时时间差(转载)

原网址 (SpringBoot返回date日期格式化,解决返回为TIMESTAMP时间戳格式或8小时时间差 https://blog.csdn.net/beauxie/article/details/78552919)

在其他方案没有解决的情况下,包括(spring boot项目使用@JsonFormat无效问题 https://blog.csdn.net/luan666/article/details/80399349)

@JSONField(format = "yyyy-MM-dd HH:mm:ss")  //FastJson包使用注解
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") //Jackson包使用注解
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")   //格式化前台日期参数注解
    private Date createTime;

解决方案:

在application.properties配置文件增加以下配置::

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

第一行指定date输出格式为yyyy-MM-dd HH:mm:ss;

第二行指定时区,解决8小时的时间差问题。

记录一下!

猜你喜欢

转载自blog.csdn.net/somdip/article/details/83416759